This topic is locked

sending e-mail

2/4/2009 1:50:27 PM
PHPRunner General questions
hfg author

I am trying to send an e-mail, but my e-mail host requires authentication (where the username is the e-mail full email address) in order to do so. Can anyone help me figure this one out?
What I have so far:
ini_set('SMTP','mail.example.com');
$email="user@example.com";

$subject="Appointment Reminder";

$headers='From: webmaster@example.com' . "\r\n" .

'Reply-To: webmaster@example.com' . "\r\n" .

'X-Mailer: PHP/' . phpversion();
$message.="Just a reminder that you have an appiontment on ".$values["Appt_Date"]."\r\n";

$message.="at ".$values["Appt_Hour"]."\r\n";
mail($headers, $email, $subject, $message);

S
steveh 2/5/2009

There's a pear module that will handle all this and it's well documented.
Take a look at pear.php.net

G
gchable 2/12/2009

Usa este codigo y cuentame si te funciono:

<?php

$smtp_server = "mail.tuserver.com";

$port = 25;

$mydomain = "tuserver.com";

$username = "tumail@tuserver.com";

$password = "tupass";

$sender = "xxx@tuserver.com";


$recipient1 = "user@example.com";
$subject = "Appointment Reminder";

$content="";

$content. = "Just a reminder that you have an appiontment on ".$values["Appt_Date"]."\r\n";

$content. = "at ".$values["Appt_Hour"]."\r\n";


// Initiate connection with the SMTP server

$handle = fsockopen($smtp_server,$port);

fputs($handle, "EHLO $mydomain\r\n");



// SMTP authorization

fputs($handle, "AUTH LOGIN\r\n");

fputs($handle, base64_encode($username)."\r\n");

fputs($handle, base64_encode($password)."\r\n");



// Send out the e-mail

fputs($handle, "MAIL FROM:<$sender>\r\n");

fputs($handle, "RCPT TO:<$recipient1>\n");

fputs($handle, "DATA\r\n");



fputs($handle, "To: $recipient1\n");

fputs($handle, "Subject: $subject\n\n");

fputs($handle, "$content\r\n");

fputs($handle, ".\r\n");



// Close connection to SMTP server

fputs($handle, "QUIT\r\n");

?>