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 Quote Link to comment 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 = "test@tets.com"; $to = "mail@someone.com"; $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 Quote Link to comment 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? Quote Link to comment 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.. Quote Link to comment 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?? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted April 1, 2010 Share Posted April 1, 2010 try this <?php $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> Quote Link to comment 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? Quote Link to comment 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.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.