I want to send php mail with template below is my code
<?php
// sending email
$SendFrom = "MyWebsite <no-reply@mywebsite.com>";
$SendTo = "$user_email";
$SubjectLine = "Welcome Email Activation";
// Build Message Body from Web Form Input
$MsgBody='Hello, <br/> <br/> Your are most welcome to Mywebsite.com<br/> <br/> Before you continue kindly activate your email by clicking on the below link or copy and paste it in your browser and hit enter for your email activation to take place.<br/> <br/> <a href="'.$base_url.'activation/index.php?code='.$activation.'">'.$base_url.'activation/index.php?code='.$activation.'</a>';
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
?>
Notice that i using a simple php code and not PDO as it is working for me Thanks, any help will be appreciated.
For display html an email, you need define this info in the header, Content-type: text/html; charset=utf-8
$headers = "From: no-reply@mywebsite.com" . "
";
$headers .= 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=utf-8' . "
";
mail($SendTo, $SubjectLine, $MsgBody, $headers);
mail()
function is kind painfull, there are other better options like, PHPMailer or swiftmailer this libs are easy to use and you don't need config headers bullshit.
<?php
function sendEmail(**$SendTo, $SubjectLine, $MsgBody,$SendFrom**)
{
$mail = null;
$mail = new PHPMailer(true);
$mail->IsSMTP();
try
{
$mail->Host = "Host Name Enter"; // SMTP server
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
// sets the SMTP server
$mail->Port = 2525; // set the SMTP port for the GMAIL server
$mail->Username = "Enter SMTP Username"; // SMTP account username
$mail->Password = "Enter Password"; // SMTP account password
$mail->AddAddress($SendTo);
$mail->SetFrom($SendFrom, 'Subject To'**);
$mail->Subject = $subject;
// $mail->AddEmbeddedImage('uploads/'.$res['user_img'], 'prf');
// <img height='100' width='100' style='border 5px solid gray;' `enter code here`src='cid:prf' alt='' />
$mail->MsgHTML($MsgBody);
return $mail->Send();
} catch (Exception enter code hereon $e)
{
echo $e;
}
$mail->ClearAllRecipients();
}
?>
-----------
OR
-----------
$SendFrom = "To: $msgTo
";
$SendFrom .= "From: no-reply@email.com
";
$SendFrom .= "Bcc: $bcc
";
$SendFrom .= "X-Mailer: PHP".phpversion();