Page 1 of 1

Need Help In PHP Mail

Posted: Sun Nov 22, 2009 1:39 am
by viniyo
Hi,

I would require an urgent help for mailing.

When I try to mail from my website email to my other website email; the email is sent successfully.

But, when I am trying to send an email from my website email to my gmail it fails.

I know it can be done using some manipulation in the PHP code. I had done that earlier but have missed the code :( and am banging my head :banghead: like anything since the last 1 month.. Any one please help.

The php.ini settings are below:

[mail function]
; For Win32 only.
SMTP = mail.mywebsite.com
smtp_port = 25

; For Win32 only.
sendmail_from = contact_us@mywebsite.com

The code that i am using to send the mail is:

<?
$to = "ynsinghbtech@gmail.com";
$subject = "Your emal has been sent!";
$body = "This is a test";
if(mail($to,$subject,$body)){
echo "<b>PHP has sent your mail</b>";
}else{
echo "<b>PHP could not send your mail</b>";
}
?>


The error that i am receiving is:

Warning: mail() [function.mail]: SMTP server response: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server. in C:\webs\02_test\test.php on line 5
PHP could not send your mail.

Please Help.

Re: Need Help In PHP Mail

Posted: Mon Nov 23, 2009 9:26 am
by AbraCadaver
The SMTP server requires authentication. You'll probably need to use an SMTP library or write your own in order to be able to supply a username and password. PEAR has one: http://pear.php.net/package/Mail

-Shawn

Re: Need Help In PHP Mail

Posted: Mon Nov 23, 2009 1:27 pm
by qianbc2007
Sending Mail from PHP Using SMTP Authentication - Example(using phpmailer)

Code: Select all

[color=#FF0000]$mail->SMTPAuth   = true[/color];                  // enable SMTP authentication
 
        $mail->Host       = "mail.sample.net"; // sets the SMTP server
        $mail->Port       = 587;                    // set the SMTP port for the mail server
        [color=#FF0000]$mail->Username   = "sample@sample.net"[/color]; // SMTP account username
        [color=#FF0000]$mail->Password   = "123";[/color]  
actually,you can test sending email first using authentication on Outlook,make sure everything is working on Outlook.

Posted: Mon Nov 23, 2009 1:29 pm
by Jonah Bron
Or, use Swiftmailer