Jump to content

problem with emailing


kryppienation

Recommended Posts

Hello everyone, i'm trying to just run a very simple email script to send a message, it's not working properly i keep getting the "mail failed" when i run the script. Can anyone tell me what's wrong?

 

<?php


//define the receiver of the email
$to = '[email protected]';


//define the subject of the email
$subject = 'Test email'; 


//define the message to be sent. Each line should be separated with \n
$message = "Hello."; 


//define the headers we want passed
$headers = "From: [email protected]\r\nReply-To: [email protected]";


//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );


//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";


?>

Link to comment
https://forums.phpfreaks.com/topic/162831-problem-with-emailing/
Share on other sites

Remove the @ in front of the function call because that would hide any error that would tell you why it failed and add the following two debugging lines of code immediately after your first opening <?php tag -

 

ini_set("display_errors", "1");
error_reporting(E_ALL);

i got the following results when i did those things.

 

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 C:\htdocs\kryppienation\testemail.php on line 23

Mail failed

 

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);


//define the receiver of the email
$to = '[email protected]';


//define the subject of the email
$subject = 'Test email'; 


//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail."; 


//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: [email protected]\r\nReply-To: [email protected]";


//send the email
$mail_sent = mail( $to, $subject, $message, $headers );


//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";


?>

I sure do, i'm wondering if i didn't set something up right in the php.ini file? I'm not really sure what to look for in there, do you have any advice on what needs changed or anything? This is the first time that i've tried to incorperate email into the code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.