Please ssssssssss help me for php mail function

Discussion in 'PHP' started by Om ji Kesharwani, Dec 14, 2009.

  1. #1
    I want to send mail to my gmail account from my website but it s giving some error please check it http://www.visitallahabad.com/contact.php

    My code is
    <?php
    require_once "Mail.php";
    
    $from = "Sandra Sender <contact@visitallahabad.com>";
    $to = "Ramona Recipient <o.jkesharwani@gmail.com>";
    $subject = "Hi!";
    $body = "Hi,\n\nHow are you?";
    
    $host = "mail.visitallahabad.com";
    $username = "contact@visitallahabad.com";
    $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:

     
    Om ji Kesharwani, Dec 14, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    The request is not able to reach to smtp.

    Check whether your smtp server is listening to port 25 only or on some other port?

    Alternately, you can try phpmailer keeping debug mode on for detailed error analysis.

    PHPMailer
     
    mastermunj, Dec 14, 2009 IP
  3. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Please tell me how to check wether smtp server is listening to port 25 or not...
     
    Om ji Kesharwani, Dec 15, 2009 IP
  4. AlexKey

    AlexKey Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can use fsockopen() php function (see official manual at php.net/fsockopen) to check if there's some answer at 25 port. And you can specify the timeout, for example, 1 second (by default it's 30 sec).
     
    AlexKey, Dec 15, 2009 IP
  5. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #5
    gmail smtp requires TLS
     
    javaongsan, Dec 15, 2009 IP
  6. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #6
    Why not just use PHP's native mail() function?
     
    Wogan, Dec 16, 2009 IP
  7. Chris S. Taylor

    Chris S. Taylor Peon

    Messages:
    20
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Exactly, why are you complicating things. Just use the simple mail() function in PHP to send Contact-Us feedback to your email account. If you would like a ready made script, let me know -- i will send it to you.
     
    Chris S. Taylor, Dec 17, 2009 IP
  8. yoes_san

    yoes_san Peon

    Messages:
    443
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Is it me or PEAR are not available on that many hosting?

    Just use standard PHP mail() though, that should be enough for your everyday's needs.
     
    yoes_san, Dec 17, 2009 IP
  9. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    mail() is working fine with the email id related to my own domain i.e but when i am using ID like or yahoo.com its not working.

    My requirement is to recieve mails to my gmail ID.
     
    Om ji Kesharwani, Dec 25, 2009 IP
  10. yoes_san

    yoes_san Peon

    Messages:
    443
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Gmail needs ssl and port 465

    I just update my script today and found out that to use gmail you'll need to set the followings:

    use this as host (add the "ssl://"):
    "ssl://smtp.gmail.com"

    And use this for Mail::factory
    
    $smtp = Mail::factory('smtp',
        array ('host' => $host,
        'auth' => true,
        'port' => '465',
        'username' => $username,
        'password' => $password));
    
    PHP:
    Hope this helps
     
    yoes_san, Dec 25, 2009 IP
  11. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #11
    Now a days mail( ) is not working in many servers.. bcz they prefers through smpt...

    there is some risk in using mail( ) ...... :D
     
    strgraphics, Dec 25, 2009 IP
  12. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Thanks Chris S. Taylor . If you can please provide me script.

    My requirement:
    when i approve the selected members a welcome mail should be send to their email ID.
    Email Id may be yahoo,gmail, hotmail etc...
     
    Om ji Kesharwani, Dec 26, 2009 IP