How to send email via PHP script using PHPMAILER

How to send email via PHP script using PHPMAILER?

You can send email using PHPMAILER from your PHP script with SMTP to use PHPMAILER Classes, you just need to download PHPMAILER class files from the following URL: 

 

https://github.com/PHPMailer/PHPMailer 

You can see the sample code below for your PHP script with SMTP authentication :

 

<?php

    require("class.phpmailer.php");

    $mail = new PHPMailer();

 

    $mail->IsSMTP();                      // send via SMTP

    $mail->Host     = "smtp.domain.com"; // SMTP servers

    $mail->SMTPAuth = true;     // turn on SMTP authentication

    $mail->Username = "email@domain.com";   // SMTP username

    $mail->Password = "password"; // SMTP password

 

     $mail->From     = "email@domain.com";

     $mail->FromName = "Name";

     $mail->AddAddress("Recipient@emailaddress.com","Name");

     $mail->AddReplyTo("yourname@domain.com","Your Name");

 

     $mail->WordWrap = 50;                 // set word wrap

 

     $mail->IsHTML(true);                     // send as HTML

 

     $mail->Subject  =  "Here is the subject";

     $mail->Body     =  "This is the <b>HTML body</b>";

     $mail->AltBody  =  "This is the text-only body";

 

     if(!$mail->Send())

    {

                                 echo "Message was not sent <p>";

                                echo "Mailer Error: " . $mail->ErrorInfo;

                                exit;

     }

echo "Message has been sent";

 

?>

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Configure email account on Android mobile phone

You can follow these steps to configure your email account on your Andriod mobile phone. -...

Configuring the email account on your iPhone

Please follow these steps to configure your email account on your iPhone. - Please go to...

Add a POP3 account in your Gmail account

- Please login into your Gmail account and click on the "settings" button on the right side of...

Configure an email account in Mac Entourage

Please Go to "Entourage/Account Settings" After please click on the "New/Configure account...

Configure an email account in Mac Mail

- Please go to "Mail/Preferences" - Please go to "Accounts" -  -  Please click "+" to add a...