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 forwards 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...';
}
?>
Related
I write a script to send email from my website. I recieve email in inbox in gmail, outlook and hotmail but in yahoo, its going to SPAM folder and also URL in not working in yahoo. Whats wrong in my code,
Header
$headers = "MIME-Version: 1.0 \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$headers .= "From: $Name <$Email> \r\n";
$headers .= "Reply-To: $Email\r\n";
Message with URL
$message.= "<a href='https://www.google.com'>Click here</a>";
PHP-Mail function is not uses a well configured SMTP Server so may be this is a reason or try to Use the PHPMailer-Class. or you need to try with full headers
Also links not working cause your mail in spam. need to move in inbox and see.
http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/
For more info follow:- sending email via php mail function goes to spam
I have used used the PHP Language for Sending the email and HTML tags are not rendering in the gmail account sometimes.I have used Content Type as - charset="iso-8859-1" I have attached the image.
And also am receiving the Message ID, which should not be come in the mail.
I don't recommend/use php built in mail() function to send and receive emails. Use php open source libraries like PHPMailer and SwiftMailer. I have been using PHPMailer after facing many issues when using mail() alone. Very easy to implement and has lots of features. You don't have to spend your valuable time for email sending related development.
http://phpmailer.worxware.com/
http://swiftmailer.org/
If the HTML isn't rendering, that usually means the headers weren't set properly.
Try this:
<?php
//change this to your email.
$to = "m#m.com";
$from = "m#m.com";
$subject = "This is HTML email";
$message = "
<b>htmlemail....</b> <br>
<a href='http://www.google.com'>Google</a>";
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
mail($to, $subject, $message, $headers);
echo "Message sent..";
?>
From http://www.webhostingtalk.com/showthread.php?t=416467
So when I execute this without modifying the header information to send html type emails it sends however when I have it send with it being an html email it never gets sent.
here is the code:
<?php
$to = "someone#gmail.com";
$subject = "Order Confimation - mywebsite.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <contact#mywebsite.com>";
$message = "
<!DOCTYPE html>
<html lang='en-us'>
<head>
<meta charset='utf-8'>
<title>Order Confirmation</title>
<style type='text/css'>
//style information
</style>
</head>
<body>
<div class='box'>
<h1 class='right'>Thanks!</h1>
//Blah blah blah
</div>
</body>
</html>
";
mail($to, $subject, $message, $headers);
if (mail($to, $subject, $message, $headers)) {
echo "<p class='hide'>E-mail Sent</p>";
} else {
echo "<p class='hide'>Problem</p>";
}
?>
And it returns E-mail sent however the email never goes to the inbox
Any suggestions?
Also pear package is enabled.
There's nothing wrong with your code as written above (with the exception that you call mail() twice - once outside the error check loop, once inside the 'if' - so you send 2 emails)
A quick test delivered fine to a Google Apps email address, so there's nothing about the code that specifically should be causing problems.
Spam filtering is a cumulative game. There can be multiple small things wrong none of which mark you as spam, but cumulatively tip your score over the limit.
In this case, you're sending a solely HTML email without a text/plain component. This is a negative mark against your score which seems to be acting as the straw to break the camel's back. If you're sending from a shared host with poor reputation you may get a few more points against you, and your PHP mail settings may be pushing an invalid return-path or other origin-based error which also count against.
You could try sending a multipart with both text/plain and text/html per http://krijnhoetmer.nl/stuff/php/html-plain-text-mail/
If that doesn't work, then if you post the full headers of the successful plaintext email then I might be able to see if you have other indicators.
Gmail will accept most mail, but just blackhole it after acceptance, so if you're using that to test you won't get much feedback.
Email's a tricky game, and if you're needing to get delivered for your app's success, you may want to consider using a third party service:
http://SendGrid.com
http://PostageApp.com
http://PostmarkApp.com
These services are designed around sending event-driven email from apps and handling all the mess on the ISP delivery end.
Full Disclosure: I am the Deliverability guy at PostageApp
I noticed you don't have
$headers .= 'To: ';
Could that have something to do with it?
I think you need to include the SMTP settings for outgoing mail if you are using mail function in php. So technically your mail will be reported as sent but would not have gone through the mail provider.
(I know you need to do that in java when using the mail function.)
mail function returns true, so you should say :
// mail() function return 0 if all right, so compare this with 0
if (mail($to, $subject, $message, $headers)) {
echo "E-mail Sent";
} else {
echo "Problem";
}
Not :
if (mail($to, $subject, $message, $headers)==0)
I am trying to send new system generated password using mail() in php. The thing is I am able to send it to yahoo but when I use gmail or hotmail I dont receive any emails although the function returns true. Following is the function:
if(mail($to,$subject,$body))
{
return true;
}
else
{
return false;
}
It probably ends up in the spam folder look there. If its there make sure your email headers are perfect.
You could look into librairies for what you want to achieve. Zend_Mail has everything you could need to connect to gmail and others.
If you are getting the mail successfully through yahoo, you should also post the headers that are coming through from yahoo here in the question. My bet is you will need to include a "from field" also to get through on hotmail, gmail, etc...
Your problem might be the antispam filters. E-mails sent from PHP are usually marked as spam by the mail servers and end up deleted or in the spam can.
You can Google for "php mail spam" to get some hints of how to work around this issue.
Maybe you're on a shared server and the IP is banned/blocked due to spamming by other users (websites) of your server.
Try adding SPF records.
Ensure that your envelope-FROM (a.k.a. return path) is set to a valid email address that you have access to. If you're not seeing the message in the spam folders, it should be getting bounced; the bounce message may offer a clue as to why the mail is not getting through.
I would try to include your own headers in your mail function
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Date: ". date('r'). " \r\n";
$headers .= "Return-Path:youremail#domain.com\r\n";
$headers .= "Errors-To:youremail#domain.com\r\n";
$headers .= "From:youremail#domain.com <youremail#domain.com>\r\n";
$headers .= "Reply-to:youremail#domain.com \r\n";
$headers .= "Organization: YourOrg \r\n";
$headers .= "X-Sender:youremail#domain.com \r\n";
$headers .= "X-Priority: 3 \r\n";
$headers .= "X-MSMail-Priority: Normal \r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($to,$subject,$body,$headers);
Try checking if your mailserver ip is blacklisted anywhere?
http://www.mxtoolbox.com/blacklists.aspx
If not, try harder with the headers that are being sent with the mail.
I have a website in which I send a confirmation mail as part of the registration process.
Some time ago, I had some troubles with the mails I sent since I used no headers (PHP mail function).
Once I put some headers, I've gotten more responses from users, but I suspect that not every message reaches its destination.
How can I be sure that the messages reach their destination?
Which are the headers that can be considered a 'must'?
This is the code of my SendMail function
mail($to,
$subject,
$message,
"MIME-Version: 1.0\n".
"Content-type: text/plain; charset=ISO-8859-1; format=flowder\n".
"Content-Transfer-Encoding: 8bit\n".
"Message-Id: <" . md5(uniqid(microtime())) . "#mysite.com>\n".
"Return-Path: <admin#mysite.com>\n".
"X-Mailer: PHP v".phpversion()."\n".
"From: admin# mysite.com");
You should use external library for working with e-mails in php like PhpMailer , SwiftMailer or Zend_Mail. All your problems will go away.
The headers need a white space at the bottom to separate the header from main body.
Tools like Spam Assassin will give you a big mark down for that.
Also you should use \r\n as a line terminator instead of just \n
From PHP.net
Multiple extra headers should be separated with a CRLF (\r\n).
The headers seems quite good to me. The only glitch I see is an extra whitespace in the From header.
I'm sure you already checked it, but just in case ...
"From: admin# mysite.com");
should be (?)
"From: admin#mysite.com");
This is a working mail function I'm using for html mail and variable $return is defined to get error report from mail server in case of fail delivery.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$from.'>' . "\r\n";
$return = '-f'.$from;
#mail($to, $subject, $msg, $headers, $return);
you can see more detail at here sugunan.com
The headers look ok, except for the details pointed by #Eineki. Also if you are using Windows you need to send the $to param in the form "user#mail.com" and not "Username ", because it may cause trouble, due to the way the mail() function is implemented on windows platform, the "to" address may be parsed incorrectly.
You should add a Date: header (its mandatory by RFC5322) and some mail-clients may assume January 1 1970 as an e-mail date if none is given (and it gets lost between all the other old messages).