1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php mail() not sending mail

Discussion in 'PHP' started by Vizuke, Oct 11, 2007.

  1. #1
    hi, i have a function that uses the php mail() function but it doesn't seem to be sending the mail. i'm not sure if i have to create the email account in cpanel or not but from what i've seen, it doesn't uses SMTP. ive seen many simple tutorials online and this is as simple as it gets but i guess not simple enough for my script to work. anyone knows what is wrong? or how i can fix this?

    
    function smail($post) {
      $to = $post['email'];
      $subject = "activation code";
      $message = "Activation code: ".$post['activationcode'];
      $from = "activate@mywebsite.com ";
      $headers = "From: $from";
      if(mail($to, $subject, $message, $headers)) { echo 'success'; }
      else { echo 'deny'; }
     }
    
    PHP:

     
    Vizuke, Oct 11, 2007 IP
  2. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What PHP error or warning do you get?

    If none then turn warnings and errors on, this will be very useful information and it will be easier for us to help you.
     
    Greg Carnegie, Oct 12, 2007 IP
  3. Vizuke

    Vizuke Peon

    Messages:
    339
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't get any warnings. I get the debugging message "deny" that I added.
     
    Vizuke, Oct 12, 2007 IP
  4. le_gber

    le_gber Peon

    Messages:
    28
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    could it be the space in the from field?
     
    le_gber, Oct 12, 2007 IP
  5. Noddegamra

    Noddegamra Peon

    Messages:
    1,013
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    im pretty sure it should be $_POST['example'] and not $post['example']
     
    Noddegamra, Oct 12, 2007 IP
  6. Noddegamra

    Noddegamra Peon

    Messages:
    1,013
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You also need..

    
    $headers .= "X-Mailer: php";
    
    PHP:
     
    Noddegamra, Oct 12, 2007 IP
  7. Cooker

    Cooker Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Maybe mail(); is blocked in PHP.ini ?
     
    Cooker, Oct 12, 2007 IP
  8. TechEvangelist

    TechEvangelist Guest

    Messages:
    919
    Likes Received:
    140
    Best Answers:
    0
    Trophy Points:
    133
    #8
    You might need more mime info in the headers, but I don't think this will stop the mail function from sending the message. I've always used the folowing to build the headers and have never had a problem. You should also correct all of the other issues that people identified.

    $headers = "";
    $headers .= "From: $from\n";
    $headers .= "Reply-To: $from\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";

    Try displaying all of your variable values before script reaches the mail function. Something is not being fed correctly. I suspect that the $to value is missing.
     
    TechEvangelist, Oct 12, 2007 IP
  9. xxclixxx

    xxclixxx Peon

    Messages:
    28
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    If you have a firewall, check that you didn't firewall off the ports it uses to send the mail. I think I might have done that to mine yesterday..
     
    xxclixxx, Oct 12, 2007 IP
  10. Squash

    Squash Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You can try to contact support on your hosting about this issue.

    Also can you look your php.ini file and look section about sendmail. Also you can use phpinfo() function. Can you say what you have near following variable

    sendmail_path ?
     
    Squash, Oct 12, 2007 IP
  11. Vizuke

    Vizuke Peon

    Messages:
    339
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    This is my sendpath output from phpinfo()

    sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i

    All the variables I outputted onto the screen and it's correctly filled in. The mail doesn't sends though.
     
    Vizuke, Oct 13, 2007 IP
  12. Squash

    Squash Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    SO please try to contact hoster support. They can look sendmail log and say does this problem with sendmail ot this is problem with your code.
     
    Squash, Oct 13, 2007 IP
  13. dineshsjce

    dineshsjce Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    refer to the page http://top-answers.net/webhost/web-hosting.html for PHP script to send mails
     
    dineshsjce, Dec 19, 2011 IP
  14. thegr4

    thegr4 Well-Known Member

    Messages:
    695
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    133
    #14
    Sometimes the hosting does not allow php to send emails, although php does not show any error but it does not work. They disable this function to prevent from misuse in the form of spam. Sometimes they only allow it to be used for the same domain emails like, if your domain is world.net the script will only work if the recipient and sender email in the function is @world.net

    Confirm from your hosting provider.
     
    thegr4, Dec 23, 2011 IP