rahul_jjj Posted December 23, 2008 Share Posted December 23, 2008 I am new to Php and I am using php5 with apache. I wanted to have a code which can send an email automatically from the system.. I have the below code with me... $to = "[email protected]"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = 'From: .'."test".' <[email protected]>'; $headers = "From: $from"; mail($to,$subject,$message,$headers); Can anyone advise me on this as I am not able to send eny email with this. Link to comment https://forums.phpfreaks.com/topic/138164-how-to-send-an-email-from-php5/ Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 $to='[email protected]'; $subject='This is a subject string'; $message='This is the body'."\n\n".'On multiple lines'; $headers='From: Your Name <[email protected]>'."\r\n"; $headers.='Reply-To: Your Name <[email protected]>'."\r\n"; $headers.='Reply-Path: Your Name <[email protected]>'."\r\n"; if (mail($to,$subject,$message,$headers)) { echo 'Sent.'; } else { echgo 'Failed.'; } Link to comment https://forums.phpfreaks.com/topic/138164-how-to-send-an-email-from-php5/#findComment-722202 Share on other sites More sharing options...
rahul_jjj Posted December 23, 2008 Author Share Posted December 23, 2008 I tried the same and it says "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 " What all do I have to configure in php.ini file ? Link to comment https://forums.phpfreaks.com/topic/138164-how-to-send-an-email-from-php5/#findComment-722219 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Sounds like the settings aren't quite there - hopefully someone will be able to help you with this one as I've never had this error. Link to comment https://forums.phpfreaks.com/topic/138164-how-to-send-an-email-from-php5/#findComment-722221 Share on other sites More sharing options...
PravinS Posted December 23, 2008 Share Posted December 23, 2008 Upload on any php supporting server and check. SMTP is not configured on you local machine so u r getting that error Link to comment https://forums.phpfreaks.com/topic/138164-how-to-send-an-email-from-php5/#findComment-722223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.