开发者

How to test if email is send (or received)?

开发者 https://www.devze.com 2023-04-10 04:57 出处:网络
below is a part of a website where orders are sent to a small a computer that prints the email out directly on a receiptprinter.

below is a part of a website where orders are sent to a small a computer that prints the email out directly on a receiptprinter.

The problem is that sometimes (1 in 50 times) the email is never printet, even though you are send to the kvittering.php page.

Any ideas of how I can make a test, that only for开发者_StackOverflow中文版wards you to the kvittering.php if the email is 100% sent? Then I can eliminate the website as a source of error and focus on the printer. Any advice is welcome.

<?php
$headers = "From: www.testsite.dk \r\n";
$headers.= "Content-Type: text/plain; charset=iso-8859-1 ";
$headers .= "Content-Transfer-Encoding: 8bit ";
$body = "$name_field\nTel. $phone_field\n$email_field \nVil gerne bestille følgende:$menucard_to\nMed følgende ændringer\n $message";
header("Location: $redirect_field"); 
mail($to, $subject, $body, $headers);

?>
<script>
<!--
  window.location= "kvittering.php"
//-->
</script>


orders are sent to a small a computer that prints the email out directly on a recieptprinter.

I'd strongly suggest you to choose one of hundreds more convenient and secure protocols, such as FTP, SSH XML-RPC, HTTP or any other.

If you can't you have to:

  • study the particular mailserver serviong this "small a computer"
  • obtain one of hundreds PHP SMTP scripts interacting with SMTP manually and use it instead of mail().
  • study it's return values and check them with your sending code


Probably, you can try embedding 1px image in e-mail and point its path to a PHP script which should trace opening an email (which means successful delivery) and deliver 1px blank PNG. You can find information on such READTAG on the net. Hope it will help you.


Use PHPMailer class at first and connect to SMTP server some how. Maybe you can get an access to same SMTP where the printer is connected. And move header() function after mail() function.

EDIT: Here is the article about redirects.


The most basic way to check if the e-mail has been sent is just:

<?php
$headers = "From: www.testsite.dk\r\n";
$headers.= "Content-Type: text/plain; charset=iso-8859-1\r\n";
$headers.= "Content-Transfer-Encoding: 8bit";
$body = "$name_field\nTel. $phone_field\n$email_field \nVil gerne bestille følgende:$menucard_to\nMed følgende ændringer\n $message";
if(mail($to,$subject,$body,$headers))
{
    header("Location: $redirect_field"); 
    echo'
<script>
<!--
window.location= "kvittering.php"
//-->
</script>';
}
else
{
    echo'Error...';
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消