php not sending email

Discussion in 'PHP' started by wordgeist, Jul 14, 2010.

  1. #1
    I'm trying to implement this script to send email:

    
    <?php
    $to = "myemail@gmail.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "myemail@gmail.com";
    $headers = "From: $from";
    $sentmail = mail($to,$subject,$message,$headers);
    
    // if your email succesfully sent
    if($sentmail){
    echo "Email Has Been Sent .";
    }
    else {
    echo "Cannot Send Email ";
    }
    
    ?>
    
    
    PHP:
    I ran the script using "php -q mail.php" and the output I have is Email Has Been Sent but I never get the email. any of you knows what can it be wrong?
     
    wordgeist, Jul 14, 2010 IP
  2. phpl0v3r

    phpl0v3r Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you need to have smtp server running on your system :)
     
    phpl0v3r, Jul 14, 2010 IP
  3. mahdi_fci3

    mahdi_fci3 Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi all, thank you phpl0v3r
    I have also this problem, but what is smtp server, and how to know if the server of my site has smtp or not ?
     
    mahdi_fci3, Jul 15, 2010 IP
  4. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Telnet to port 25. If you can't connect then ask support if they are running it on another port.

    If you don't have an SMTP daemon installed locally - use googles. Search for 'PHP google smtp'.
    This is probably a better solution as googles SMTP servers are usually white listed, making the deliverability higher.

    Where as your hosting server probably has a few hundred more people sharing it, and if one of them decides to send out spammy messages - they've also blacklisted you.
     
    Deacalion, Jul 15, 2010 IP
  5. sanhit

    sanhit Peon

    Messages:
    318
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    please check the spam folder, may be ip of your host is blacklisted. If you need php email form PM me I will send you the working code.
     
    sanhit, Jul 16, 2010 IP
  6. nimonogi

    nimonogi Active Member

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    80
    #6
    nimonogi, Jul 17, 2010 IP
  7. mahdi_fci3

    mahdi_fci3 Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks all
    but I dont understand spam folder and how to see if my host is blacklisted so can u give me the details please ?
     
    mahdi_fci3, Jul 25, 2010 IP
  8. master-mind

    master-mind Well-Known Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #8
    Basically, create a new testing page without form. setup some dummy variables. use a working example from online tutorials. and try it.

    some times your server requires return address too before sending an email actually. so you will have to define -r parameter with your returning email.

    if you need more assistance, PM me with your code and I will be able to help.

    thanks
     
    master-mind, Jul 25, 2010 IP
  9. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    According your code, you can send the mail....!!!
    Make sure smtp server, nothing more than that.
     
    strgraphics, Jul 26, 2010 IP
  10. manzar

    manzar Peon

    Messages:
    111
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    use this mail function.
    <?php

    //Check whether the submission is made
    if(isset($hidSubmit)){

    //Declarate the necessary variables
    $mail_to=$txtEmailto;
    $mail_from=$txtEmailfrm;
    $mail_sub=$txtSub;
    $mail_mesg=$txtMsg;

    //Check for success/failure of delivery
    if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
    echo "<span class='red'>E-mail has been sent successfully from $mail_sub to $mail_to</span>";
    else
    echo "<span class='red'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
    }
    ?>
     
    manzar, Jul 27, 2010 IP
  11. vocongdanh

    vocongdanh Member

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #11
    If you run the code in localhost, it's not work !
     
    vocongdanh, Jul 27, 2010 IP
  12. infocusweb

    infocusweb Guest

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    there are many errors in your code..
     
    infocusweb, Jul 27, 2010 IP
  13. ze0xify

    ze0xify Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I'd recommend against using mail() and going with PHPMailer's library. Chances are that anything sent by your server will be blacklisted or marked as spam unless you've setup a mailserver and can do signing from it. SMTP to a signed mail server will keep your messages out of spam and isn't hard to implement. A lot of hosting companies offer a SMTP server to use.

    It could also be from Gmail filtering out your message because it sees it as spam (fyi).
     
    ze0xify, Jul 27, 2010 IP