Please help me in Php mail() fuction

Discussion in 'PHP' started by Om ji Kesharwani, Nov 1, 2009.

  1. #1
    I have created a contact us form by using mail function
    mail("contact@mydomain.com", $sub, $message, $from);

    All is well when i used above.

    But when i change email id to my gmail or yahoo email ID mail is not send.
    My requirement is to get all the mails to my gmail id, Is there any other setting to modify?
    I dont want to use mail forwarder.
     
    Om ji Kesharwani, Nov 1, 2009 IP
  2. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think its problem from your host provider..
    contact them..
     
    xenon2010, Nov 1, 2009 IP
  3. DansTuts

    DansTuts Guest

    Messages:
    923
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?
    
    // Use like you did with your old mail() function but with a few changes
    // you need to set your host, username and password to what they are on your server
    // So sendmail("contact@example.com","test@gmail.com","hello","are you ok","Message sent"); 
    // Coded by Daniel Clarke (DanMakes on Twitter)
    
    function sendmail($from,$to,$subject,$body,$eturn) { 
    
    $host = "mail.example.com";
    $username = "username";
    $password = "password";
    
    $headers = array ('From' => $from,
      'To' => $to,
      'Subject' => $subject);
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'username' => $username,
    	'auth' => true,
        'password' => $password));
    
    $mail = $smtp->send($to, $headers, $body);
    
    if (PEAR::isError($mail)) {
      return $mail->getMessage(); 
     } else {
      return TRUE; 
     }
     
    }
    
    ?>
    PHP:
     
    DansTuts, Nov 1, 2009 IP
  4. Om ji Kesharwani

    Om ji Kesharwani Peon

    Messages:
    211
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I am new to php please tell me what is
    $host = "mail.example.com";
    $username = "username";
    $password = "password";

    from where i can get hostname?
     
    Om ji Kesharwani, Nov 1, 2009 IP
  5. bashex

    bashex Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Normally your script should work. But, as the other poster mentioned, check with your hosting provider so they troubleshoot the mail server on your hosting, otherwise provide you with the right settings.
     
    bashex, Nov 1, 2009 IP
  6. gacba

    gacba Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Some specifics to check before talking to your hosting provider:
    - Is the SPF record for the domain setup correctly? (Check your SPF record: http://www.mxtoolbox.com/SuperTool.aspx)
    - Are you on a blacklist? (same tool above)

    HTH
     
    gacba, Nov 2, 2009 IP