[wd_asp elements=’search’ ratio=’100%’ id=1]

PHPMailer – Send email with attachments & images

30th November 2013

Php - Email

php codehaven

Send email using SMTP in the easiest way!

Most basic usage – UPDATED FEB 2020 (working)
Download PHPmailer from github (https://github.com/PHPMailer/PHPMailer)


setFrom('[email protected]', 'Codehaven test');
$mail->addAddress('[email protected]', 'Sid');
$mail->Subject = 'Your report';
$mail->Body = 'Hello',

If you have any questions, please do not hesitate to contact us.

';

$mail->isSMTP(); /* SMTP server address. */
$mail->Host = 'smtp.gmail.com';
/* Use SMTP authentication. */
$mail->SMTPAuth = TRUE;
/* Set the encryption system. */
$mail->SMTPSecure = 'tls';
/* SMTP authentication username. */
$mail->Username = '[email protected]';
/* SMTP authentication password. */
$mail->Password = 'YOURPASSWORD';
/* Set the SMTP port. */
$mail->Port = 587;

$mail->isHTML(true);
// xxxxxxxxxxxx ADD ATTACHMENT

$mail->addAttachment('mini1.gif');
$mail->addAttachment('images/mini2.gif');

//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

}
catch (Exception $e)
{
echo $e->errorMessage();
}
catch (\Exception $e)
{
echo $e->getMessage();
}

?>

And with attachments