I extracted the PHPMailer zip in my server root and created the contact.php file to handle the contact form data but when i submit the form i get an error not one i used in my catch block get this error Oops! An error occured and your message could not be sent. i, need some help setting up the PHPMailerin my server. Here’s my contact.php
code
<?php use PHPHMailerPHPMailerPHPMailer; use PHPMailerPHPMailerException; require 'PHPMailer/src/Exception.php'; require 'PHPMailer/src/PHPMailer.php'; require 'PHPMailer/src/SMTP.php'; $mail = new PHPMailer(true); try { // $mail->SMTPDebug = 0; $mail->isSMTP(); $mail->Host = 'sxb1plzcpnl473190.prod.sxb1.secureserver.net'; $mail->SMTPAuth = true; $mail->Username = 'info@***.co.za'; $mail->Password = '***'; $mail->SMTPSECURE = 'tls'; $mail->Port = 587; // receipt $mail->setFrom('My Mail'); $mail->addAddress($_POST['email']); // content $mail->isHtml(true); $mail->Name = $_POST['name']; $mail->Phone = $_POST['phone']; $mail->Email = $_POST['email']; $mail->Subject = $_POST['subject']; $mail->Body = $_POST['message']; $mail->send(); // echo message has been sent // header('Location: www.***.co.za'); echo 'alert("Thank You For Contacting US, Will Get Back To You Within 24Hours")'; exit(); } catch (Exception $e) { echo 'Failed To Send Contact Info, Please Try Again'; } ?>
Advertisement
Answer
GoDaddy imposes very strict (to the point of becoming almost useless) constraints on sending an email. They block outbound SMTP to ports 25, 465 and 587 to all servers except their own. This problem is the subject of many frustrating questions on Stack Overflow. The solution is extremely poorly documented by GoDaddy: you must send through their servers, and also disable all security features, username, and password (great, huh?!), giving you this config for PHPMailer:
$mail->isSMTP(); $mail->Host = 'localhost'; $mail->SMTPAuth = false; $mail->SMTPAutoTLS = false; $mail->Port = 25;
GoDaddy also refuses to send with a From address belonging to any aol, gmail, yahoo, hotmail, live, aim, or msn domain (see their docs). This is because all those domains deploy SPF and DKIM anti-forgery measures, and faking your from address is forgery.
For more details: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#godaddy