no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | blog:php_mail_function [2009/11/27 17:53] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== PHP mail and ISP relays ====== | ||
+ | |||
+ | This did my head in so I thought it worthy of a small write up. | ||
+ | |||
+ | Here the problem: //I wanted to send an email from a DRUPAL 5.12 site hosted on a home linux configured with sendmail/ | ||
+ | |||
+ | Sounds simply enough. | ||
+ | |||
+ | Here is my simple test program in PHP to send an email. | ||
+ | <code php> | ||
+ | <?php | ||
+ | $Name = "Da Duder"; | ||
+ | $email = " | ||
+ | $recipient = " | ||
+ | $mail_body = "The text for the mail..."; | ||
+ | $subject = " | ||
+ | $header = "From: ". $Name . " <" . $email . "> | ||
+ | |||
+ | mail($recipient, | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | Doesn' | ||
+ | |||
+ | <box 80% green round> | ||
+ | |||
+ | **/ | ||
+ | < | ||
+ | Dec 3 16:05:53 elmo postfix/ | ||
+ | Dec 3 16:05:53 elmo postfix/ | ||
+ | Dec 3 16:05:53 elmo postfix/ | ||
+ | Dec 3 16:05:53 elmo postfix/ | ||
+ | Dec 3 16:05:53 elmo postfix/ | ||
+ | </ | ||
+ | |||
+ | You see that the envelope-sender is actually **apache@elmo.local** this address is checked by **yo@company.com** spam's filter says "Hay that not valid I'll reject that". | ||
+ | |||
+ | So what you need to do is tell sendmail that it should use the " | ||
+ | |||
+ | Small modification to the PHP and this is done. Why did that take me an hours to figure out? God only knows. | ||
+ | <code php> | ||
+ | mail($recipient, | ||
+ | </ | ||
+ | |||
+ | So back to DRUPAL the PHP **mail()** function is wrapped by the function **drupal_mail()** in the **includes/ | ||
+ | |||
+ | So we tweak the invokation like so: | ||
+ | |||
+ | <code php> | ||
+ | function extract_email_from($string){ | ||
+ | preg_match_all("/ | ||
+ | return $matches[0][0]; | ||
+ | } | ||
+ | |||
+ | function drupal_mail($mailkey, | ||
+ | |||
+ | .. snip .. | ||
+ | |||
+ | return mail( | ||
+ | $to, | ||
+ | mime_header_encode($subject), | ||
+ | str_replace(" | ||
+ | join(" | ||
+ | '-f ' | ||
+ | ); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Reference: http:// | ||
+ | |||
+ | {{tag> | ||