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.
<? // 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:
I am new to php please tell me what is $host = "mail.example.com"; $username = "username"; $password = "password"; from where i can get hostname?
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.
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