Need Help In PHP Mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
viniyo
Forum Newbie
Posts: 1
Joined: Sun Nov 22, 2009 1:32 am

Need Help In PHP Mail

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need Help In PHP Mail

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
qianbc2007
Forum Newbie
Posts: 3
Joined: Tue Nov 17, 2009 6:54 pm

Re: Need Help In PHP Mail

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

Or, use Swiftmailer
Post Reply