Browsed by
Tag: PHP Function

PHP Mailer Function

PHP Mailer Function

Dummy content goes here
The only PHP function that supports this is the mail() function. However, it does not provide any assistance for making use of popular features such as HTML-based emails and attachments.

Formatting email correctly is surprisingly difficult. There are myriad overlapping RFCs, requiring tight adherence to horribly complicated formatting and encoding rules – the vast majority of code that you’ll find online that uses the mail() function directly is just plain wrong! Please don’t be tempted to do it yourself – if you don’t use PHPMailer, there are many other excellent libraries that you should look at before rolling your own – try SwiftMailer, Zend_Mail, eZcomponents etc.

$mail = new PHPMailer();
$mail->SMTPDebug = 0; //Enabled this so you can see what's happening - Dont forget to set to 0 in production
$mail->IsSMTP();             // set mailer to use SMTP
$mail->SMTPSecure = 'ssl';  
$mail->Host = "";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Port = 465;
$mail->Username = "";  // SMTP username
$mail->Password = "*******"; // SMTP password
$mail->From = "";
$mail->FromName = "HRMS";
$mail->AddAddress($to);                 // name is optional
$mail->AddReplyTo("", "Information");                 
//$mail->AddReplyTo("", "Information");// name is optional

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
$mail->IsHTML(true);                                  // set email format to HTML

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