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 trialahmed suleiman
Courses Plus Student 11,685 PointsPHP mailer
I using Gmail & SMTP with PHP mailer to send email from my app, I am able to get email from my Contact page but the problem is it redirects me to Contact page full of Server information instead of contact.php?status=thanks" here is my code
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 a name, email address, and message";
exit;
}
foreach($_POST as $value){
if(stripos($value,'Content-Type:') !== FALSE){
exit;
}
}
if($_POST["address"] != ""){
echo "Your form submission has an error";
exit;
}
require_once("inc/phpmailer/class.phpmailer.php");
include("inc/phpmailer/class.smtp.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;
$body = file_get_contents('contents.html');
$body = preg_replace("[\]", '', $body);
$mail->IsSMTP(); // enable SMTP
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPDebug=1;
$mail->SMTPSecure= "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "example@gmail.com";
$mail->Password = "password";
$mail->SetFrom($email, $name);
$address = "example@gmail.com";
$mail->AddAddress($address, "firstname lastname");
$mail->Subject = "Shirts 4 Mike Contact Form Submission | " . $name;
$mail->MsgHTML($email_body);
if(!$mail->Send()) {
echo "There was a problem sending the email: " . $mail->ErrorInfo;
exit;
}
header("Location: contact.php?status=thanks");
exit;
}
Rex Soriano
3,981 PointsRex Soriano
3,981 PointsDo you have an if statement checking for the $_GET['status'] == 'thanks' ?
Try something like this. <code>
</code>