Search
 
SCRIPT & CODE EXAMPLE
 

PHP

send email template via php

<?php
$to = 'user@example.com';
$subject = "Send HTML Email Using PHP";

$htmlContent = '
<html>
<body>
    <h1>Send HTML Email Using PHP</h1>
    <p>This is a HTMl email using PHP by CodexWorld</p>
</body>
</html>';

// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "
";
$headers .= "Content-type:text/html;charset=UTF-8" . "
";

// Additional headers
$headers .= 'From: CodexWorld<info@codexworld.com>' . "
";
$headers .= 'Cc: welcome@example.com' . "
";
$headers .= 'Bcc: welcome2@example.com' . "
";

// Send email
if(mail($to,$subject,$htmlContent,$headers)):
    $successMsg = 'Email has sent successfully.';
else:
    $errorMsg = 'Email sending fail.';
endif;
?>
Comment

create email template php

$variables = array();

$variables['name'] = "Robert";
$variables['age'] = "30";

$template = file_get_contents("template.html");

foreach($variables as $key => $value)
{
    $template = str_replace('{{ '.$key.' }}', $value, $template);
}

echo $template;
Comment

php mail template

php artisan make:mail MensagemTesteMail --markdown emails.mensagem-teste
Comment

send-email.php

<?php

$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];

require "vendor/autoload.php";

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;

$mail = new PHPMailer(true);

// $mail->SMTPDebug = SMTP::DEBUG_SERVER;

$mail->isSMTP();
$mail->SMTPAuth = true;

$mail->Host = "smtp.example.com";
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;

$mail->Username = "you@example.com";
$mail->Password = "password";

$mail->setFrom($email, $name);
$mail->addAddress("dave@example.com", "Dave");

$mail->Subject = $subject;
$mail->Body = $message;

$mail->send();

header("Location: sent.html");
Comment

PREVIOUS NEXT
Code Example
Php :: Notice: Trying to access array offset on value of type int in /var/www/pdam/modules/phpexcel/PHPExcel/Cell/DefaultValueBinder.php on line 82 
Php :: regex php password 
Php :: using php, how to create a folder in another folder 
Php :: php string underscore into camelcase 
Php :: how to play sound with php 
Php :: how to call a helper function in blade 
Php :: ternary operator in php 
Php :: map associative array php0 
Php :: how to prompt user for input in php 
Php :: how to make db seeder in laravel 
Php :: wp_query order by taxonomy 
Php :: PHP mysqli_close function 
Php :: php iterate thru object 
Php :: Regex For Iranian Phone Numbers 
Php :: acf get field 
Php :: foreign key laravel migration 
Php :: search function using php for database entries 
Php :: create function php 
Php :: datetime validation in laravel 
Php :: create seeder in laravel 
Php :: redirect compact laravel 
Php :: how to make classess in php 
Php :: how to change taxonomy slug in wordpress 
Php :: Wordpress admin settings form 
Php :: laravel handle queryexception 
Php :: how to get all post fields in wordpress 
Php :: subtract string php 
Php :: brew install php 5.6 
Php :: php generating number 
Php :: AUTO_INCREMENT in laravel 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =