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 trialPat Rick
2,570 PointsError sending an email. Everything was going well until I tried to send a message to a gmail.
GOT THIS ERROR "Message could not be sent.Mailer Error: Could not instantiate mail function."
require("inc/phpmailer/class.phpmailer.php");
$mail = new PHPMailer;
if (!$mail->ValidateAddress($email)) {
echo "Ivalid email address";
exit;
}
$email_body = "";
$email_body .= "Name " . $name . "\n";
$email_body .= "Email " . $email . "\n";
$email_body .= "Telephone " . $tel . "\n";
$email_body .= "Comments " . $message . "\n";
$mail->setFrom($email, $name);
$mail->addAddress('********61@gmail.com', 'Sean');
$mail->isHTML(false);
$mail->Subject = 'hdhhdhshshsh from ' . $name;
$mail->Body = $email_body;
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
// To Do: Send email
header("location:contact.php?status=thanks");
}?>
<?php
if (isset ($_GET["status"]) && $_GET["status"] == "thanks") {
echo "<center><p> Thanks for the email! I’ll check out your suggestion shortly! </p></center>";
} else { ?>
Moderator Edit: Added Markdown to code snippet so that it is readable in the Community post --- also obscured personal information within post... placing personal information (i.e. email address) in a publicly accessible forum is not a good idea, as it opens you up to scammers, spammers, and bots.
Radulescu Ramona
3,687 Pointssame thing happened to me.. I've tried your method, Victoria Loisi, but it didn't work.
Victoria Loisi
7,070 PointsVictoria Loisi
7,070 PointsHi there! I would start by inserting everything inside a try/catch statement, like this:
Also, have you tried
$phpMailer->Send()
instead of$phpMailer->send()
?