0

I'm having the most difficult time trying to find the error in this php form. I edited it in every possible way and the form submits on my website, however I am never in receipt of any sent form to my email. Would someone be so kind as to look over the code below for my mail.php form? TIA

Amanda

<?
require("class.phpmailer.php");


//form validation vars
$formok = true;
$errors = array();

//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');

//form data
$name = $_POST['name']; 
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];


$mail = new PHPMailer();

$mail->IsSMTP();                                         // send via SMTP
$mail->Host     = "smtp.gmail.com";                      // SMTP   server
$mail->SMTPAuth = true;                                    // turn on SMTP authentication
$mail->SMTPSecure = 'tls';
$mail->Username = "dont.reply.m@gmail.com";                  // SMTP username
$mail->Password = "password";                            // SMTP password

$mail->From     = "dont.reply.m@gmail.com";              // SMTP username
$mail->AddAddress("mypersonalemail@msn.com");                // Your Address
$mail->Subject  =  "New Message from your website!";
$mail->IsHTML(true);  
$mail->CharSet = 'UTF-8';
$mail->Body     =  "<p>You have recieved a new message from the contact form on your website.</p>
                  <p><strong>Name: </strong> {$name} </p>
                  <p><strong>Email Address: </strong> {$email} </p>
                  <p><strong>Subject: </strong> {$subject} </p>
                  <p><strong>Message: </strong> {$message} </p>
                  <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";

if(!$mail->Send())
{
echo "Mail Not Sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Mail Sent";


?>
Ares
  • 5,905
  • 3
  • 35
  • 51
  • So are you getting `Mail Sent` printed on the page after the form submisison? – asprin May 30 '14 at 04:13
  • I hope you are not testing this on localhost – Shairyar May 30 '14 at 04:17
  • Duplicate of http://stackoverflow.com/questions/16048347/send-email-using-gmail-smtp-server-through-php-mailer – Mysteryos May 30 '14 at 04:17
  • @asprin Yes I receive the mail sent notification when submitting test messages. It somehow just won't send it to my email so I don't know if I'm getting any inquiries via contact form or not. – 5h1t5 n' 9199le5 May 30 '14 at 04:28
  • @Baig localhost? I have it uploaded to my server. – 5h1t5 n' 9199le5 May 30 '14 at 04:29
  • Checked your spam folder as well? – asprin May 30 '14 at 04:30
  • @Mysteryos I saw it was a duplicate and I tried to reply to that poster's question with my inquiry as to resolution to the issue (we apparently are using the exact same template) however the moderator removed my question and said it wasn't an 'answer to the poster's question and I need to post it as a separate question.' Kinda sucky IMO. – 5h1t5 n' 9199le5 May 30 '14 at 04:30
  • @user3413623 I have the email info filled out correctly on the php form (my email addresses and passwords) i had however just replaced it for purposes of confidentiality. – 5h1t5 n' 9199le5 May 30 '14 at 04:32
  • @asprin Not in spam either :/ – 5h1t5 n' 9199le5 May 30 '14 at 04:36
  • I FIXED IT!!!!!! Just tweaked some things and it works fine now. I do however have an issue with my newsletter subscription on my website though. It now (finally) delivers inquiries to my email address, however it only shows the ip address where the inquiry came from and not the users email address. :( Anyone? – 5h1t5 n' 9199le5 May 30 '14 at 05:28

2 Answers2

0

Try to add $mail->Port = 587 and refer the following link.Sometimes $mail->SMTPSecure should be SSL in case o gmail other than TLS

This is complete reference for Send email using Gmail settings

Send email using GMail for PHP mailer

Gmail Settings

Geo V L
  • 866
  • 8
  • 25
  • I changed tls to ssl on the line $mail->SMTPSecure, but where would I add $mail->Port = 587 ? Thanks for your help. – 5h1t5 n' 9199le5 May 30 '14 at 04:34
  • It can be add just below that $mail->SMTPSecure Line $mail->Port = 587 and I hope you did it already – Geo V L May 30 '14 at 11:52
  • I didn't, but the form works. I'm having an issue with the field input info showing up in my submissions though (ex. someone signs up for newsletter and inputs their email in the email field - it shoots an email over to me, and it shows the ip address, but not the email address they entered.) Any advice? – 5h1t5 n' 9199le5 May 30 '14 at 18:44
0

If you are testing it in localhost make sure you have a mail server installed.

If in online try using valid info

$mail->Host     = "smtp.gmail.com";                      // SMTP   server
$mail->SMTPAuth = true;                                    // turn on SMTP authentication
$mail->SMTPSecure = 'tls';
$mail->Username = "dont.reply.m@gmail.com";                  // SMTP username
$mail->Password = "password";                            // SMTP password

$mail->From     = "dont.reply.m@gmail.com";              // SMTP username

replace those for the reals

user3413623
  • 80
  • 1
  • 2
  • 10