Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    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.";
    ?>

    .

  • #3
    New Coder
    Join Date
    Nov 2010
    Location
    United Kingdom
    Posts
    31
    Thanks
    0
    Thanked 9 Times in 8 Posts
    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!";

    Last edited by tropane; 09-21-2011 at 09:29 PM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •