Moshambi
01-21-2009, 08:47 AM
I'm trying to learn how to send email using PHP. Here is the code:
<?php
if(isset($_GET["sub"]))
{
$to = "blaaaah@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: sender@example.com\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers)){
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
}
?>
Here are the settings I have in my php.ini :
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "D:\XAMPP\xampp\sendmail\sendmail.exe -t"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
And finally here is the error I'm getting:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\XAMPP\xampp\htdocs\practice\test.php on line 13
I don't understand how all this stuff works or what I need to do to fix it. Help is appreciated, thanks!
<?php
if(isset($_GET["sub"]))
{
$to = "blaaaah@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: sender@example.com\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers)){
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
}
?>
Here are the settings I have in my php.ini :
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "D:\XAMPP\xampp\sendmail\sendmail.exe -t"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
And finally here is the error I'm getting:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\XAMPP\xampp\htdocs\practice\test.php on line 13
I don't understand how all this stuff works or what I need to do to fix it. Help is appreciated, thanks!