Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Pedro Baumann
12,815 PointsPHPmailer godaddy -> google business
Hello Rendy and everyone else. I was building a new website on godaddy and I was just polishing the final details, thus I decided it was the right time to set up PHPmailer as I learned in the PHP videos (it worked that time).
The problem is that even though I have been googleing all around and trying different tutorials and StackOverflow answers I cannot seem to make it work.
the addres I'm working with is my google business account which domain is hosted by godaddy.
I have tried sending it through google smtp server as well as godaddy relay server, actually I have so many different configurations now that I don't know all the combinations I tried.
I'll copy my code here in case anyone can help me!!!
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);
if ($name == "" OR $email == "" OR $message == "") {
echo "You must specify a value for name, email address, and message.";
exit;
}
foreach( $_POST as $value ){
if( stripos($value,'Content-Type:') !== FALSE ){
echo "There was a problem with the information you entered.";
exit;
}
}
if ($_POST["address"] != "") {
echo "Your form submission has an error.";
exit;
}
require_once("includes/class.phpmailer.php");
$mail = new PHPMailer();
if (!$mail->ValidateAddress($email)){
echo "You must specify a valid email address.";
exit;
}
$email_body = "";
$email_body = $email_body . "Name: " . $name . "<br>";
$email_body = $email_body . "Email: " . $email . "<br>";
$email_body = $email_body . "Message: " . $message;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Port = "465";
$mail->Username = "contact@mydomainatgodaddy.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->AddReplyTo($email, $name); // Adds a “Reply-to” address. Un-comment this to use it.
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress($email, $name);
$mail->Subject = "Pedido de relxingtissues";
$mail->Body = $email_body;
if ($mail->Send() == false){
echo "The email message has NOT been sent for some reason. Please try again later.";
echo "Mailer error: " . $mail->ErrorInfo;
}
?>