SMTP mail Configuration

Please follow the below steps to configure the SMTP mailing process within your server.

  1. Click Here to Download Recent phpmailer files.
  2. Create php file with below coding.
  3. Include PHPMailer Autoload file as like below coding. (This file will change based on phpmailer  version)
    <?php
    require_once("SMTP_NEW/PHPMailerAutoload.php"); // path to the PHPMailer class
    ?>
  4.  Use the below code to implement the Mailing process.
    <?php
    $mail = new PHPMailer;//$mail->SMTPDebug = 3; // Enable verbose debug output
    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = 'user@example.com'; // SMTP username
    $mail->Password = 'secret'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587; // TCP port to connect to
    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
    $mail->addAddress('ellen@example.com'); // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');
    $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 = 'Here is the subject';
    $mail->Body = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
    echo 'Message has been sent';
    }
    ?>
  5.  Follow the below STEPS to Fix the issue.While we configure it, we have tried with GMAIL SMTP as like below configuration:
    <?php
    $mail->Mailer = "smtp";
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->SMTPSecure = "ssl"; // OR $mail->SMTPSecure = 'tls';
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465;
    ?>
  6.  But, above settings displayed SMTP connection error. Then, we have tried using Port 587Then, enabled the Debug process using 
    <?php
    $mail->SMTPDebug = 1;
    ?>

     
  7.  No help, then we have discussed with server support team to confirm the OPEN PORT and SMTP Configuration details.
  8. Finally we have followed below URLs steps to fix the issue. Its related to Google URLs. Its related the enable all access permission to Google SMTP.
    https://accounts.google.com/b/0/DisplayUnlockCaptcha
    https://support.google.com/mail/answer/14257?rd=1

    Allowing less secure apps to access your account:
    https://support.google.com/accounts/answer/6010255
    https://www.google.com/settings/security/lesssecureapps (Access for less secure apps — Turn on)

Need to know below information:
1. While we configure the Gmail SMTP, it not allow to send mail “From ” another email. Like if you configured the SMTP using “xxxx@gmail.com“, sending mail default from address will be same “xxxx@gmail.com“.

If we need to change as client email, we need to create new gmail account with client name OR we need create google App with your domain OR need to configure own SMTP.
Link: https://apps.google.com/
Search keyword: Get gmail for own domain.

 

Leave a Reply

Your email address will not be published. Required fields are marked *