PHP email issue

Discussion in 'PHP' started by Codythebest, Dec 28, 2009.

  1. #1
    This little code is working fine with PHP4 but not sending with PHP5.
    What should I do to make it work with PHP5?

    
    <?php
    $FirstName=$_POST['FirstName'];
    $LastName=$_POST['LastName'];
    $Email=$_POST['Email'];
    $Phone=$_POST['Phone'];
    
    $sujet2="$FirstName $LastName asked for it!";
    
    $message2="Hi Cody ,\n\n";
    
    $message2.="My first name is $FirstName.\n";
    $message2.="My last name is $LastName.\n";
    $message2.="My email is $Email\n";
    $message2.="My phone is $Phone\n";
    $headers2="From: $FirstName $LastName<$Email>\n";
    
    mail("cody@cody.com",$sujet2,$message2,$headers2);
    
    ?>
    
    PHP:

     
    Codythebest, Dec 28, 2009 IP
  2. deuterium

    deuterium Peon

    Messages:
    123
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It looks fine to me :S - what do you mean it doesn't work in PHP5, any error(s)?
     
    deuterium, Dec 28, 2009 IP
  3. creativeGenius

    creativeGenius Well-Known Member

    Messages:
    273
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    #3
    if you have switched servers and not just php version, you should probably also check sendmail
     
    creativeGenius, Dec 28, 2009 IP
  4. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #4
    I just tested that script using PHP 5.2.11 and it sent the email.
     
    CoreyPeerFly, Dec 28, 2009 IP
  5. Codythebest

    Codythebest Notable Member

    Messages:
    5,764
    Likes Received:
    253
    Best Answers:
    0
    Trophy Points:
    275
    #5
    Shhooot...it doesn't send it with me, damnit...
     
    Codythebest, Dec 29, 2009 IP
  6. danielbuca

    danielbuca Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The code is fine, what I think is no longer good are the sendmail settings on your server.
    Also, it would be good to know what problem do you have: the mail is not sent or the mail is sent but not received. In case you do not receive it there might be a spam filter that rejects the email because of incomplete headers.
     
    danielbuca, Dec 29, 2009 IP
  7. Codythebest

    Codythebest Notable Member

    Messages:
    5,764
    Likes Received:
    253
    Best Answers:
    0
    Trophy Points:
    275
    #7
    It is not sent.

    On the other hosting, it is sent and received, so it's not a headers issue.
     
    Codythebest, Dec 29, 2009 IP
  8. megathrone

    megathrone Active Member

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #8
    for PHP5 it's ok as well. maybe trouble with your SMTP sending server?
     
    megathrone, Dec 30, 2009 IP
  9. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #9
    Does the server send any emails with other scripts?
     
    CoreyPeerFly, Dec 30, 2009 IP
  10. Codythebest

    Codythebest Notable Member

    Messages:
    5,764
    Likes Received:
    253
    Best Answers:
    0
    Trophy Points:
    275
    #10
    I have replaced my original code by this:

    
    <?php
    require_once "Mail.php";
    
    $to = "$FirstName $LastName <$Email>";
    $from = " Cody <cody@cody.com>";
    $subject = " Hello $FirstName $LastName";
    $body = "
    
    Hi Cody ,\n\n
    
    My first name is $FirstName.\n
    My last name is $LastName.\n
    My email is $Email\n
    My phone is $Phone\n
    
    ";
    
    $host = localhost
    $username = your_cpanel_username
    $password = your_cpanel_password
    
    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password));
    
    $mail = $smtp->send($to, $headers, $body);
    
    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }
    ?>
    
    PHP:
    And installing the PEAR Mail package

    Now, I'm still trying to figure out my HTML. The Content-type doesn't do any good so far.
     
    Codythebest, Dec 30, 2009 IP
  11. jonno_81

    jonno_81 Well-Known Member

    Messages:
    81
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    115
    #11
    I've had the same problem,

    I use http://phpmailer.sourceforge.net. This is a great script. I really don't use all the functionality, but it allows attachments, multiple addresses, bcc, cc, blah blah blah.

    A nice feature I use is the html setting to send html mails.

    Like I said, I only use the basics, so if you want more info you'll have to go look

    John
     
    jonno_81, Dec 30, 2009 IP