I am trying to send an HTML mail through PHP, but I can\'t seem to get it working.
This is my code:
// multiple recipients
$to = \'mail\';
I use SwiftMailer:
require_once('../lib/swiftMailer/lib/swift_required.php');
...
function sendEmail(){
//Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
$body="Dear $fname,\n\nYour job application was successful. \n\nYours,\n\nEamorr\n\n\n\n\n\n\n";
//Create a message
$message = Swift_Message::newInstance('Subject goes here')
->setFrom(array($email => "no-reply@yourdomain.com"))
->setTo(array($email => "$fname $lname"))
->setBody($body);
//Send the message
$result = $mailer->send($message);
}
You can send both plaintext and html email with ease.
I don't think you have to put the To:
line in the header as it is a parameter of the mail
function.
However some mail clients don't like light headers, here's mine which is working:
$header = 'From: "Contact" <mail>'.PHP_EOL.
'Reply-to: <mail>'.PHP_EOL.
'MIME-Version: 1.0'.PHP_EOL.
'Content-Type: text/plain; charset=utf-8'.PHP_EOL.
'Content-Transfer-Encoding: 8bit'.PHP_EOL.
'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;
Fixed.
I found this which for some reason worked perfectly on my server:
// Set The Headers:
$headers = 'From: "Me" <info@skillsexchangenetwork.net>'.PHP_EOL.
'Reply-to: <Me@Him.com>'.PHP_EOL.
'Cc: <Her @There.com>'.PHP_EOL.
'MIME-Version: 1.0'.PHP_EOL.
'Content-type: text/html; charset=iso-8859-1'.PHP_EOL.
'Content-Transfer-Encoding: 8bit'.PHP_EOL.
'X-Mailer: PHP/'.PHP_VERSION.PHP_EOL;
// Send:
mail($to, $subject, $message, $headers);
Thanks for the input guys.