Ok so I spent a short time making this survey, and setting up a form to handle sending invites for the survey out to people (to be used in house). During production it was working fine, now the emails are not showing up in our in-boxes. The mail function is still returning true, so I'm unsure of why its not showing up. None of the code has changed, and our development environment is on the exact same server as our production environment, so ini settings are all the same as well. Below is a snippet of the code, and attached is the entire file.
// Base SQL for multiple insert
$sql = 'INSERT INTO survey_invites (id_invite,invite_email,invite_token) VALUES ';
foreach( $emails as $info ) {
$token = saltyhash($info['email']);
// Send mail message to each recipient
$to = $info['email'];
$msg = buildmsg($info['name'],$token,$info['type']);
if( mail($to,$sub,$msg,$headers) )
$content .= 'Message to '. $info['name'] .' sent successfully.<br />';
else
$content .= 'Message to '. $info['name'] .' failed to send.<br />';
// Build SQL to insert email/token for validation later.
$sql .= '(NULL,\''. $info['email'] .'\',\''. $token .'\'),';
}
$sql = substr($sql,0,-1);
if( $db->query($sql) )
$content .= 'Emails and tokens successfully stored in the database.';
As I said, it was working perfectly while I was testing it, now its like the emails aren't sending, or for some reason just aren't making it to our inbox (yes we've checked our spam box as well)
i too got the same problem few months ago... it was on a hosting server which did not support From header so when i removed From header it worked as expected.
Is the "from" email address a valid email on the host where the script is running? (Many hosts are configured to only allow that so as to prevent spammers from using the host to relay email.) If this is the case, set the "From:' header to a valid email address for that host, and then add a "Reply-To:" header with the desired email.
It probably does not matter, but the "FROM:" header should be "From:".
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Well according to php.net headers shouldn't be case sensitive, but I'll give it a try. And like I said it was working in the development sub-folder which would be domain.com/dev/survey instead of domain.com/survey so the fact that it did work is what bothers me.
Anyway it seems to be working but on a delay of some sort (takes 1-2 hours to show up in the mailbox). Luckily, as long as it works its good to go for now. I wish my server supported pear::mail_mime
You might consider using the PHPMailer class, which provides a lot control and flexibility to sending emails. Also, it is possible to install PEAR packages yourself within your site's web directories without the full PEAR installation, it's just a lot more fiddly, as you have to make sure all dependencies are uploaded and the include_path is adjusted as needed (making PHPMailer look like a better deal ).
Last edited by NogDog; 06-16-2011 at 02:51 PM.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Thanks, I'll have a look at it Monday when I'm back in the office. For now sending invites with an hour or two delay isn't that big of a deal, but will definitely check it out as installing pear in a web accessible folder doesn't seem "ideal" to me.
Bookmarks