dazzathedrummer Posted April 1, 2010 Share Posted April 1, 2010 Hi, i've been google'ing for a couple of hours now and cant seem to find out how to write a script that will send an email from the server via smtp. Could anyone point me in the right direction? thanks, Darren Link to comment https://forums.phpfreaks.com/topic/197219-code-to-send-email-via-smtp-host/ Share on other sites More sharing options...
Deoctor Posted April 1, 2010 Share Posted April 1, 2010 <!-- send mail using an smtp--> <?php require_once "Mail.php"; $from = "[email protected]"; $to = "[email protected]"; $subject = "Hi!"; $body = "<h1>Hi</h1>,\n\nHow are you?"; $host = "mail.example.com"; $username = "smtp_username"; $password = "smtp_password"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?> try with this Link to comment https://forums.phpfreaks.com/topic/197219-code-to-send-email-via-smtp-host/#findComment-1035184 Share on other sites More sharing options...
dazzathedrummer Posted April 1, 2010 Author Share Posted April 1, 2010 yeah - thanks, I've tried that one - I get a server error though "500 internal server error" Is there something that I need to configure? My ISP uses sendmail, do I need to specify the path? Link to comment https://forums.phpfreaks.com/topic/197219-code-to-send-email-via-smtp-host/#findComment-1035186 Share on other sites More sharing options...
Deoctor Posted April 1, 2010 Share Posted April 1, 2010 if in ur php.ini the sendmail path is already configured then try using the program to send it through sendmail only.. by the way what hosting ur using up.. Link to comment https://forums.phpfreaks.com/topic/197219-code-to-send-email-via-smtp-host/#findComment-1035189 Share on other sites More sharing options...
dazzathedrummer Posted April 1, 2010 Author Share Posted April 1, 2010 these are my servers sendmail settings: - sendmail_from no value - no value sendmail_path - /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i serialize_precision 100 100 short_open_tag On On SMTP - localhost localhost smtp_port - 25 How do I change the code to use sendmail?? Link to comment https://forums.phpfreaks.com/topic/197219-code-to-send-email-via-smtp-host/#findComment-1035195 Share on other sites More sharing options...
Deoctor Posted April 1, 2010 Share Posted April 1, 2010 try this <?php $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> Link to comment https://forums.phpfreaks.com/topic/197219-code-to-send-email-via-smtp-host/#findComment-1035199 Share on other sites More sharing options...
dazzathedrummer Posted April 1, 2010 Author Share Posted April 1, 2010 thats works!!! excellent - so that's using the servers 'default' settings? Link to comment https://forums.phpfreaks.com/topic/197219-code-to-send-email-via-smtp-host/#findComment-1035206 Share on other sites More sharing options...
Deoctor Posted April 1, 2010 Share Posted April 1, 2010 yes it is using the sendmail of ur server instead of the smtp settings.. Link to comment https://forums.phpfreaks.com/topic/197219-code-to-send-email-via-smtp-host/#findComment-1035209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.