Jump to content

[SOLVED] why mail() doesnt work


tawevolution

Recommended Posts

Hi,

 

Im trying to use the mail() function. Here is my code:

 

<?php
$to = "email@address.co.uk";
$subject = "subject here!";
$body = "this is the body section of the email message";


if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

 

Every time i run the script, it says "Message successfully sent!".... so i then go over to my email inbox (i set the $to to my own email as a test) and the email never comes through. I have checked my email spam box, and i have tried several different email accounts (using diff email providers) .... none of which get through.

 

Someone told me to make sure the 'safe_mode' was off, and 'register_globals' was on - of which they both are ...... any ideas?????

 

Thanks

Evo

Link to comment
Share on other sites

Hello

I have just tried to run your code on my system which sows all errors for testing purposes and got the following error

Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Program Files\xampp\htdocs\phptest\mail.php on line 7

Message delivery failed...

 

try this but modify for taste

<?php
$to = "email@address.co.uk";
$subject = "subject here!";
$body = "this is the body section of the email message";
$headers = 'From: Birthday Reminder <birthday@example.com>' . "\r\n";

if (mail($to, $subject, $body, $headers)) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

Link to comment
Share on other sites

You intial code is ok.

 

Are you testing this on your own machine or on a live server? If its your own machine then check that you have set the SMTP setting in your php.ini file (set it to what ever your service providers smtp is)

Link to comment
Share on other sites

Are you testing this on your own machine or on a live server? If its your own machine then check that you have set the SMTP setting in your php.ini file (set it to what ever your service providers smtp is)

 

Its on a live server .... so what should i do to make it work?

Link to comment
Share on other sites

sorry for double post .....

 

I have marked this post as solved because I found out why it wasnt working. I was sending an email to my hostings email accounts - and it doesnt like that - so i just created temp @gmail.com accounts and set up forwarders :P

 

evo out

 

thanks for your hepl guys

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.