0

Hi guys i am using the mail() from the contact form and for some reason it is not working.

The php coding i have setup is as follows:

            // sending email to sales@xxx.com
        $to      = "hello@xxx.com";
        $subject = 'Email From {$name} from your website';
        $message = "$name has contacted you from the website and says:

        $mcontent

        $name 's contact email address is: $email"; 

        $headers = $email . "\r\n";
        $headers .= "Reply-To: " . $email . "\r\n"; 
        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

        mail($to, $subject, $message, $headers) or die ("Failure");
        // end of sending mail

        returnheader("/xxx/email-sent");  

i get no errors at all, it even goes to the success page when completed.

Any ideas why this would not work.

Robert
  • 907
  • 4
  • 13
  • 32

7 Answers7

2

I have checked your code and it is working fine on my server , i am getting e-mail. Here , it looks like some problem with your SMTP server settings. There is nothing wrong with your PHP script. You can find your solution here. php.ini & SMTP= - how do you pass username & password

Also in windows environment , http://www.ruhanirabin.com/php-sendmail-setup-with-smtp-iis-and-windows-servers/

Community
  • 1
  • 1
Milap
  • 6,915
  • 8
  • 26
  • 46
1
  • If you are on WIndows, make sure you have an SMTP server in your php.ini
  • If you are una Unix, make sure the MTA is running: If it is (at least partly) installed but not runnng, you will get exactly this effect

Edit

If your MTA is not running, and you start it, the mails sent with PHP will go out! They have beein queued, but not processed.

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
1

This is probably related to the mail setup. Do you have a mailserver running on the machine? Check sendmail / smtp_server settings in php.ini.

Eirik Hoem
  • 1,310
  • 7
  • 14
1

mail() uses the sendmail, by default: sendmail -t -i

It returns TRUE if the mail has been accepted, not if it has been sent:

Return Values

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

I would suggest using http://swiftmailer.org/ with SMTP rather than mail().

Community
  • 1
  • 1
Tim
  • 6,281
  • 3
  • 39
  • 49
  • @Tim i cant seem to get the swiftmailer to work, as far as i can see it uses smtp sendmail anyway doesnt it? When setting it up, it just gives a blank screen when submitted contact details. – Robert Feb 14 '12 at 14:29
0

You should use double quotes instead of single quotes in the variable $subject

$subject = "Email From {$name} from your website";
Colin Brock
  • 21,267
  • 9
  • 46
  • 61
0

The first line of $headers is invalid if $email is just an email address. Presumably you would want something like:

$headers = "Cc: " . $email . "\r\n";

or

$headers = "From: " . $email . "\r\n";
SimonMayer
  • 4,719
  • 4
  • 33
  • 45
0

The cause can be for example, you don't have setup a mail server, or configuration of firewall if you has it.

chenio
  • 592
  • 3
  • 11
  • 27