简体   繁体   中英

Issues with PHP contact form (won't send inquiries to my email) :(

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";


?>

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM