Email not getting through

the mail() function

Moderators: macek, egami, gesf

nick2price
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Jan 23, 2012 11:56 am

Email not getting through

Postby nick2price » Mon Jan 23, 2012 12:02 pm

Hey, I never receive email with my php code, and my host is saying that all services are up and mail is enabled. However, I am sure it is a host problem, I cannot see what else it can be. Just want to clear things up quickly though. In my root folder, I create a php file called test. Inside this file is the basic code

Code: Select all

<?php
$ADDR = "test@aol.com";
if (mail($ADDR,"Testing","This is a test")) {
echo "Mail function succeeded<br />";
} else {
echo "Mail function FAILED<br />";
}
?>


If I then navigate to the url mywebsite.com/test.php, will the php code automatically be executed? And could someone please confirm that the code is correct. When I navigate to the url, I get returned the succeeded message. So it appears it works, but the mail never gets delivered. I have tried different email addresses all with different providers.

Could anyone shed some light on what my issue may be?

Many thanks

User avatar
bigjoe11a
New php-forum User
New php-forum User
Posts: 137
Joined: Wed Aug 31, 2011 3:55 am
Location: USA
Contact:

Re: Email not getting through

Postby bigjoe11a » Sun Jan 29, 2012 1:31 pm

1st check your junk folder. Make sure that your filtered list includes the domain name from and to the email that your sending.

or if that doesn't work. Try using this. Just change the email names to the ones you want to use. Your sample above doesn't include any header information

Code: Select all

<?php
// recipients email address
$to  = 'admin@domain.com'; // note the comma


// subject
$subject = 'Subject of the message';

// message
$message = 'Type in the body of your message here';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>' . "\r\n";
$headers .= 'From: My Name <myname@domain.com>' . "\r\n";
$headers .= 'Cc: myname@domain.com' . "\r\n";
$headers .= 'Bcc: myname@domain.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest