Having some problems with a PHP script that sends emails (code below). Basically, it fills the vCard file with the contact information stored in sql db, and attaches it to the email using the php mail () function.
I had it working fine on a shared hosting server a few days ago ... but I recently switched everything to VPS and it magically stopped working. Mail () continues to return true when sent, but the actual email never arrives in my inbox.
//sendemail: emails a vCard when passed an email address and name
function sendemail($address, $scanreduser)
{
include('../dbconnect.php');
$info = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE usernum='". $usernum ."' LIMIT 1 "));
$vcard_content = "BEGIN:VCARD\r";
$vcard_content .= "VERSION:3.0\r";
$vcard_content .= "N:".$info[lname].";". $info[fname] .";;;\r";
$vcard_content .= "FN:".$info[fname]." ". $info[lname] ."\r";
$vcard_content .= "ORG:".$info[company].";\r";
$vcard_content .= "TITLE:".$info[title]."\r";
$vcard_content .= "EMAIL;type=INTERNET;type=WORK;type=pref:".$info[email]."\r";
$vcard_content .= "TEL;type=WORK;type=pref:".$info[phone]."\r";
$vcard_content .= "item2.URL;type=pref:".$info[website]."\r";
$vcard_content .= "item2.X-ABLabel:_$!<HomePage>!\$\_\r";
$vcard_content .= "X-ABShowAs:COMPANY\r";
$vcard_content .= "END:VCARD";
$email_subject = "Your vCard from " . $info[fname] . " " . $info[lname];
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = $info[fname] ."_". $info[lname] .".vcf";
$headers = "From: Ben@scanred.com";
$today = date("l, F j, Y, g:i a");
$message = "<br />Simply open the attached vCard file to view/download the information<br />";
$message .= $today." PST<br /><br />";
$message .= $info[name]."<br />";
$data = $vcard_content;
$data = chunk_split(base64_encode($data));
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
echo @mail($address, $email_subject, $message, $headers);
echo $address;
}
source
share