Tuesday, May 19, 2015

PHP Mailer SMTP Script for contact form on website that works on Godaddy

I have copied this PHPmailer script from my godaddy hosting account so it actually works well on godaddy deluxe hosting account which enables PHP execution.

3 files need to be uploaded into your godaddy hosting account where the mail script is going to reside. These are phpmailer libraries and can be found here:

https://github.com/PHPMailer/PHPMailer

PHPMailerAutoload.php
class.phpmailer.php
class.smtp.php

Only the PHPMailerAutoload.php is included in the script.

Change the hostname, username and password. You can copy these 3 from godaddy email configuration section in the hosting account.

smtp method of sending email for contact form sends the email from your website, using your website admin username. So the email never goes in to spam and is not ever considered suspicious. reply-to is the email the visitor enters on the contact form on your website, so that when you reply to the email it goes to customer not to the admin email of your website.

These 3 email addresses need to be your own:

admin@xxx.com  (email account on godaddy mail server for your website)
recipient@gmail.com  (whatever email address contact form will be send to)
$visitor_email (email address the user entered in contact form on your website)

<?php

    require './PHPMailerAutoload.php';

    if(isset($_POST['email']))

    {


    $name          = $_POST['name'];

    $phone         = $_POST['phone'];
    $visitor_email = $_POST['email'];
    $content       = $_POST['message'];



     if($visitor_email =="") {  //dont send email go back
           
              echo ("UNSUCCESSFUL:Please Enter Your Email");
         
         
             
             } else {    //try sending email


 
 $subject = "FROM Company";
 $bodytext .= $name . "<br>" . $phone . "<br>" . $visitor_email . "<br>" .  $content;
 


    $mail = new PHPMailer();
    $mail->IsHTML(true);
    $mail->isSMTP();
    $mail->SMTPDebug = 0;
 
    $mail->Host = "a2plcpnl0146.prod.iad2.secureserver.net";
    $mail->SMTPAuth = true;  
    $mail->Username = "admin@xxx.com";
    $mail->Password = "xxxxxxxx";
    $mail->port = 465;


$mail->addReplyTo($visitor_email);
$mail->setFrom('admin@xxx.com');



$mail->addAddress('recipient@gmail.com');
$mail->Subject = $subject;
$mail->Body = $bodytext;


 
 
   
 
              if($mail->Send()) {
              echo ("You message was sent SUCCESSFULLY");
             
             } else {
              echo ("Technical Problems:Your message was not sent");
             }

}
}
?>