After my domain's fsockopen was open open, I have been trying to get hold of a PHP script that can send simple text mails without any framework (PEAR etc). I could not find any on this forum.
The couple of scripts found on internet did not work. The following is a working script after some trial and error attempts with SMTP servers. I have also tried to indicate the reasons for failure of other scripts. Hope it helps.
Go to this page - http://fiate2000.110mb.com/work.php and then click on PHP Code - Send simple text mail with PHP fsockopen
While you are there, you can also look at other code examples.
Edit - code added to this post <?php
$smtp_server = "mail.mymailserver.com";
$mydomain = "any_text_here";
//get the following info from your mail server eg. au.yahoo.com
$port = 25; //SMTP PORT of mail.mymailserver.com
$username = "myusername"; $password = "mymail_password";
$sender = "myusername@mymailserver.com";
/*
Most respectable mail servers will reject outgoing mail
if $sender e-mail address does not belong to $username
*/
$sender_name = "My Name"; //Any name you fancy
$recipient = "your.friend@someother.com";
$subject = "the subject";
$content = "the message";
// SMTP connection
$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:$recipient\r\n");
fputs($handle, "DATA\r\n");
fputs($handle, "From: $sender_name<$sender>\r\n");
//you can use different e-maill address in above line, but most spam blockers will suspect this
fputs($handle, "To: $recipient\r\n");
fputs($handle, "Subject: $subject\r\n");
fputs($handle, "$content\r\n");
fputs($handle, ".\r\n");
//Don't ignore the period "." in line above. This indicates the end of your mail
// Close connection to SMTP server
fputs($handle, "QUIT\r\n");
?>
For more useful scripts -
you can visit my webpage.