View Full Version : Trying to get mail() function to work - any ideas ?

02-24-2008, 03:56 PM
I have been trying to use the following code to send an email out after someone fills in a form:

* make MESSAGE

$messageX = "testing";

* send MESSAGE

// multiple recipients
$to = $N_email;

// subject
$subject = "As Promised ...Your Free Access to LETS GET STARTED.";

// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";

// Additional headers
$headers .= "From: Lets-Get-Started. <Admin@lets-get-started.net> \r\n";

// Mail it
mail($to, $subject, $messageX, $headers);

echo "To: $to, Subject: $subject, Headers: $headers, Message: $messageX";

if (mail($to, $subject, $messageX, $headers) == false)
echo "Email failed";


Is there anything wrong with code ?

The code does not error - but just does not send anything

The result from the echo stmt:is :

To: kevin@intaccs.com,
Subject: As Promised ...Your Free Access to LETS GET STARTED.,
Headers: MIME-Version: 1.0 Content-type: text/html; charset=iso-8859-1
From: Lets-Get-Started. ,
Message: test

Well I cant see anything wrong.

The "if / false" does not echo anything

Is there something I should check with my hosting account ?
I have a shared hosting and have access to cPanel and even the WHM ( I have a reseller account)

Thanks again for any help

02-24-2008, 06:36 PM

For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time. If you use another mail program, such as qmail or postfix, be sure to use the appropriate sendmail wrappers that come with them. PHP will first look for sendmail in your PATH, and then in the following: /usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib. It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary.

Do you meet those?

02-24-2008, 07:39 PM
Thanks for your reply.

I ran phpinfo.php and got this information.

open_basedir /home/letsget/:/usr/lib/php:/usr/local/lib/php:/tmp
include_path .:/usr/lib/php:/usr/local/lib/php

sendmail_path /usr/sbin/sendmail -t -i
SMTP localhost
smtp_port 25

Does that mean I have access to what I need for mail() ?

Do I need to change the include_path at all ?

Thanks again

02-24-2008, 08:14 PM
// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";

you are missing a period in the first one.. not sure if thats causing the problem, but its worth checking ;)