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

PHP

Mailer error, could not instantiate mail function

$mail->setFrom($email, $name); $mail->addAddress('jordanolson1@gmail.com', 'Jordan'); // Add a recipient

$mail->isHTML(false);                                  // Set email format to HTML

$mail->Subject = 'Thank you for your email, ' . $name;
$mail->Body    = $email_body;

if(!$mail->send()) {
    echo 'Message could not be sent. ';
    echo 'Mailer Error: ' . $mail->ErrorInfo;

    exit;
} 

Pretty sure it's cuz I set my recipient address as my email address, but I keep getting the error:

Message could not be sent. Mailer Error: Could not instantiate mail function.

I am currently using MAMP. I don't have any idea what to put for the values in 'addAddress'. Dunno what to do here

Hey Jordan,

This error is due to your php configuration. Open your php.ini file and find the following line parameters :

SMTP smtp_port sendmail_from

Maybe some others.

If they are commented (start with a semi colon), just delete the semi colon and put the right value for these parameters. After that, save your php.ini file and just restart apache to be sure that changes has been loaded.

Adebayo Ojo
Adebayo Ojo
23,661 Points

I just followed Kevin Rambaud suggestion and it works!!!! I edited my php.ini file and changed the SMPT and smtp_port, restarted my apache and bang...........that's it.

2 Answers

Unfortunately that didn't solve the issue, I found out it's because of the code:

$mail->Body = $email_body;

When I remove the above line of code from the first example, it goes through to the thank you page, but I don't think it actually goes through the email sending process.

Well, if you remove this line, the email you're trying to send won't have any text in body. Check if you've entered value in $email_body variable and check your smtp parameters. If they are not defined, your email system won't work.