Log in

View Full Version : email not being received and no error message is returned.



Jim Weinberg
04-19-2017, 04:54 PM
I'm sending emails through my website and it works for most of the recipients. However, I've run into one (on hotmail) that doesn't receive it and no error message is received from the destination mail server (as it is if I send from my personal email).

What I want to know is what I need to do to receive error messages if the emails are not delivered.

Here's the code I'm using:



chdir('../../Dealer');
$myFile = "InvitationTemplate.rtf";
$myFile1 = "DealersList.txt";
$myFile2 = "Dealer_Files/Invitation Letter.rtf";
$fh1 = fopen($myFile1, 'r') or die("can't open file $myFile1");
while (!feof($fh1)) {
$fh = fopen($myFile, 'r') or die("can't open file $myFile");
$fh2 = fopen($myFile2, 'w') or die("can't open file $myFile2");
$message1 = fgets($fh1);
$pos = strpos($message1, ',');
$name = substr($message1,0,$pos);
$email = substr($message1,$pos+1);
$email = str_replace("\n", '', $email);
while(!feof($fh)) {
$message = fgets($fh);
if (strpos($message, 'Dear') !== false){
$message = str_replace('Dear','Dear ' . $name,$message);
}
fwrite($fh2,$message);
}
fclose($fh);
fclose($fh2);

//Insert email code here
$files = array("Dealer_Files/Invitation Letter.rtf","Dealer_Files/Application Request.pdf","Dealer_Files/Dealer Contract.pdf");
$types = array("rtf","pdf","pdf");
// email fields: to, from, subject, and so on
$to = $email;
$from = "dealer_chair@ohiobuttons.org";
$subject ="Dealer Information Package";
$message = "\n\nAttached please find your Dealer Package.\n\nThis email was generated automatically.\n\nIf you have any problems with this email or its attachments, please contact webmaster@ohiobuttons.org or\nsimply reply to this email.\n";
$headers = "From: $from";

// boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";

// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";

// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb");
$data = fread($file,filesize($files[$x]));
fclose($file);
$data = chunk_split(base64_encode($data));
$attachment = strpos($files[$x], '/');
$attachment = substr($files[$x],$attachment+1);
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$attachment\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$attachment\"\n" . "Content-Type: application/{$types[$x]};\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}

// send
$ok = mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Email sent to $name at $to!</p>";
} else {
echo "<p>Email could not be sent to $name at $to!</p>";
}
}

fclose($fh1);
?>


Would appreciate any help/advice on this.

Thanks.

Deadweight
04-20-2017, 02:00 AM
Any chance you can provide the email? If you dont want to display it publicly then PM me it.

Jim Weinberg
04-20-2017, 06:40 PM
Hi DW.

Thanks for the response. I'm currently working with my server's tech support. If they can't solve the problem on their end, I'd be happy to PM you the email. I'll post what the outcome is.

Thanks again,
Jim

Deadweight
04-20-2017, 09:49 PM
Okay feel free to PM when ever.