Dynadot

Hate php's bulit in mail function? I do! Here!

Spaceship Spaceship
Watch

axilant

Account Closed
Impact
28
If you dont know anything about php, please contact me if you need help. This is very basic to use. If your good at php and still need help please contact me via pm.

PHP:
<?php 
//some little vars
$cfg = array(); // dont delete or edit  this
$cfg[sitedomain] = ""; //your domain used, used for the noreply

//to use this:
  // $toArray format --> array("Name1" => "address1", "Name2" => "address2", ...)
//$toArray will carry the addresses you will be sending to and names
function socketmail($toArray, $subject, $message) {



  ini_set(sendmail_from, "root@$cfg[sitedomain]");

  $connect = fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno, $errstr, 30) or die("Could 

not talk to the sendmail server!");
   $rcv = fgets($connect, 1024);

  fputs($connect, "HELO {$_SERVER['SERVER_NAME']}\r\n");
   $rcv = fgets($connect, 1024);

  while (list($toKey, $toValue) = each($toArray)) {

   fputs($connect, "MAIL FROM:$cfg[admin_email]\r\n");
     $rcv = fgets($connect, 1024);
   fputs($connect, "RCPT TO:$toValue\r\n");
     $rcv = fgets($connect, 1024);
   fputs($connect, "DATA\r\n");
     $rcv = fgets($connect, 1024);

   fputs($connect, "Subject: $subject\r\n");
   fputs($connect, "From: No-Reply <root@$cfg[sitedomain]>\r\n");
   fputs($connect, "To: $toKey  <$toValue>\r\n");
   fputs($connect, "X-Sender: <root@$cfg[sitedomain]>\r\n");
   fputs($connect, "Return-Path: <root@$cfg[sitedomain]>\r\n");
   fputs($connect, "Errors-To: <root@$cfg[sitedomain]>\r\n");
   fputs($connect, "X-Mailer: PHP\r\n");
   fputs($connect, "X-Priority: 3\r\n");
   fputs($connect, "Content-Type: text/plain; charset=iso-8859-1\r\n");
   fputs($connect, "\r\n");
   fputs($connect, stripslashes($message)." \r\n");

   fputs($connect, ".\r\n");
     $rcv = fgets($connect, 1024);
   fputs($connect, "RSET\r\n");
     $rcv = fgets($connect, 1024);
  }

  fputs ($connect, "QUIT\r\n");
   $rcv = fgets ($connect, 1024);
  fclose($connect);
  ini_restore(sendmail_from);
}

?>
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Ummm I'm not sure I'm grasping the concept of this topic... :-P
 
0
•••
to send mail through php without using the "mail" function
 
0
•••
lol. thats self explanitory, hehe
 
0
•••
Awesome function. Thanks axilant!

I don't generally have a problem using PHP's built-in mail function, but on occasion I work with a client whose settings are off or it doesn't work reliably -- usually a Windows NT server. This could help in those situations.
 
0
•••
If there privacy settings are incorrect, it intends to not send some times. It gets annoying, because people email me i didnt get my email with my confirmation link yet!, its been 5 days or something, since ive used this, nothing like that has happen :)
 
0
•••
shouldnt this
$cfg[sitedomain] = ""; your domain used, used for the noreply
be
$cfg[sitedomain] = ""; //your domain used, used for the noreply

??
 
0
•••
if i remember correctly php automatically accepts it as a comment if it comes after the ; but yes you are right I think it should have the slashes
 
0
•••
i love the mail function, but thats just imo
 
0
•••
I like this alternative

but no prob with mail function
 
0
•••
I also found this on php's site a while back. I used it for myimgs.com to send out confirmation links due to the fact a lot of people said they were not recieving the emails.
 
0
•••
hmm the php mail function works properly if setup correctly, so people should be getting emails.

Also, it has to have the comment markers, because php doesn't automatically take it in as a comment, because you can do stuff like $blah="test"; $abc="def"; all on one line
 
0
•••
looks like I was thinking of the php.ini file

anything after the ; in that is considered a comment.
 
0
•••
adam_uk said:
shouldnt this
$cfg[sitedomain] = ""; your domain used, used for the noreply
be
$cfg[sitedomain] = ""; //your domain used, used for the noreply

??

fixed, thanks, And yes you can set it up, to have comments right after ; as long as theres not more than 1 spaces before it starts ;)
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back