Category Archives: php

501 5.5.4 Invalid Address when including Sender Name on Windows Server + PHP mail + IIS SMTP or MS Exchange

An interesting issue I came across the other day was that PHP was complaining giving a 501 5.5.4 Invalid Address error when trying to send email. The server uses IIS SMTP and the sender specified using the From: header ie
From: Me
Just specifying the email by itself works fine:
From: [email protected]

It turns out that this is a conflict between IIS SMTP and PHP. You need to specify a from email address separately by setting the ini configuration sendmail_from (for the MAIL FROM: command I presume) ie.

function mail2($from_address, $from_name, $to_address, $subject, $message, $headers) {
$old_sender = ini_get(‘sendmail_from’);
ini_set(‘sendmail_from’, $from_address);
$headers = "From: " . $from_name . " <" . $from_address . ">\r\n" . trim($headers);
mail($to_address, $subject, $message, $headers);
ini_set(‘sendmail_from’, $old_sender);

Presumably this is not an issue on UNIX as the external sendmail program handles delivery.

Which words have the letter P in it and what’s the percentage?

Another code snippet from the useless dept, this time for PHP. If you’ve ever written a post and wondered how many words use the letter P (or any character), here’s something for you in PHP:
function find_words_with_letters($letter, $str) {

$a = preg_split("#[ \n\r]+#", $str);

$letterupper = strtoupper($letter);
$letterlower = strtolower($letter);

$result = array();
$result[‘word_count’] = count($a);
$result[‘words_with_letter’] = array();

foreach($a as $i) {
if (strpos($i, $letterlower) !== false || strpos($i, $letterupper) !== false) {
$result[‘words_with_letter’][] = $i;
$result[‘words_with_letter_ratio’] = count($result[‘words_with_letter’]) / count($a);

return $result;

// use it
print_r(find_words_with_letters(‘p’, ‘This message has one P’));


By the way, 17.3% of this post have P’s in it!