Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-21-2011, 02:45 PM   PM User | #1
sunnynosid
New Coder

 
Join Date: Sep 2011
Posts: 50
Thanks: 4
Thanked 0 Times in 0 Posts
sunnynosid is an unknown quantity at this point
Question Problem in email form

I tried this to send an email to yahoo from my website:

<?php
$to = "myfriend@yahoo.com";
$subject = "Test mail";
$message = "Hello! What's going on nowadayz?";
$from = "me@mysite.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

But, my friend did not get any email from mysite, not even in his spam folder. Why this is so? Help me please. And provide me the correct code too if possible.

Last edited by sunnynosid; 09-21-2011 at 03:06 PM.. Reason: mis spelled
sunnynosid is offline   Reply With Quote
Old 09-21-2011, 06:28 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I think it might be a time-out issue with mail().
By using an "if" statement, it has to finish and return with a true or false.

Try this and see what happens:
PHP Code:
<?php
$to 
"myfriend@yahoo.com";
$subject "Test mail";
$message "Hello! What's going on nowadayz?";
$from "me@mysite.com";
$headers "From:" $from;
if(!
mail($to,$subject,$message,$headers)){
echo 
"Mail did not send for some reason.";
exit;
}

echo 
"Mail Sent.";
?>

.
mlseim is offline   Reply With Quote
Old 09-21-2011, 09:27 PM   PM User | #3
tropane
New Coder

 
Join Date: Nov 2010
Location: United Kingdom
Posts: 31
Thanks: 0
Thanked 9 Times in 8 Posts
tropane is an unknown quantity at this point
As far as I know, all this websites such as, yahoo, gmail and etc. are doing their best to prevent any spam and if they wont like your mail, you wont even be able to see it in spam folder. so what I've did was this, set the headers and it worked...!!!
PHP Code:
$email "someone@somewhere.org"// TO
$subject "MAIL SUBJECT"// Subject
$message "MESSAGE TO SOMEONE, LIKE WELCOME TO www.codingforums.org"//Message
                
//Email Headers
$headers "MIME-Version: 1.0\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
$headers .= "Date: "date('r'). "\n";
$headers .= "Return-Path:your@email.com\n";//wtf?
$headers .= "Errors-To:your@email.com\n";//If sending will fail, any errors will be send to this email
$headers .= "From:FromWho <your@email.com>\n";
$headers .= "Reply-to:replty@yourweb.com\n"//Reply email, basicaly if user will click on button reply it will be sended to this email
$headers .= "Organization: ORGANIZATION\n"//basicly your organization, but i believe it will work without it
$headers .= "X-Sender:email@somewhere.org\n"//SENDER EMAIL (your email e.g. info@yourweb.com
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: PHP/" phpversion();
//as you can see nearly after each line, there is \n, leave it like that, dont add \r, otherwise your users who use gmail wont get anything
//Email Headers End

if (mail($email$subject$message$headers))//SEND MAIL
{
    
//if successfull show this message
   
echo "Mail was send successfully!";

else 
{
    
//if unsuccessfull
    
echo "Mail was send UNsuccessfully!";

__________________
http://www.edwardtorba.com/

Last edited by tropane; 09-21-2011 at 09:29 PM..
tropane is offline   Reply With Quote
Reply

Bookmarks

Tags
code, email, error, form

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:09 AM.


Advertisement
Log in to turn off these ads.