views:

34

answers:

0

I'm learning to make websites and I'm putting together a simple website for my parents business. I made a contact form and the message is just emailed to my parents' email. I just looked up a sample gmail php code to send mail and it works when I test it with MAMP, but when I upload it to the live site, I get this error:

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

Why doesn't it work on the live site, but it works when I test it on MAMP> Here's my code:

require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host       = "myparentswebsite.com"; 
$mail->Mailer = "smtp";      
$mail->Host = "ssl://smtp.gmail.com";  
$mail->Port = 465;

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "paswsword"; // SMTP password

$webmaster_email = "[email protected]"; //Reply to this email ID
$email= $_POST['email']; // Recipients email ID
$name= $_POST['name']; // Recipient's name 
$mail->From = $webmaster_email;
$mail->FromName = "parentswebsite";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap

$mail->IsHTML(true); // send as HTML
$mail->Subject = "Feedback from parentswebsite.com";
$mail->Body = $_POST['name']. " " .$_POST['email']. " ". $_POST['phone']. "            ".             $ _POST['message'] ;//HTML Body

echo "it works"; 
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "We have received your message!";
}

Thanks all in advance!