/    Sign up×
Community /Pin to ProfileBookmark

Mail() & gmail

Using the attached code below I’m sending an HTML email using PHP. It works fine, except with Gmail. If the email is sent to a Gmail account the email contents are blank and sender is unknown. I’ve looked around and it seems there is some widespread issue but i haven’t found an answer/solution. Any help or light shed on this would be great.

[code=php]
<?PHP
//lots of stuff before this including variable setting, which all are working properly

$to = $email;
$subject = ‘Your claim is in process!’;
$random_hash = md5(date(‘r’, time()));
$headers = “From: The Insurance AgencyrnReply-To: [email protected]”;
$headers .= “rnContent-Type: multipart/alternative; boundary=”PHP-alt-“.$random_hash.”””;
ob_start();
?>
–PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset=”iso-8859-1″
Content-Transfer-Encoding: 7bit

Dear <?PHP echo $fname?>,
Thank you for submitting your claim on our website. We’re sorry to hear about your loss on <?PHP echo $dateofloss ?>; our office has received your information and will contact you as soon as possible.Sincerely,
Brian R Miller, Priciple
–PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset=”iso-8859-1″
Content-Transfer-Encoding: 7bit

<img src=”http://beta.XXXXXXX.com/img/uniform/emailhead.gif” alt=”” />
<p style=”font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:15px 0 5px 0;”>Dear <?PHP echo $fname ?>,</p>
<p style=”font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:0;”>Thank you for submitting your claim on our website. We’re sorry to hear about your loss on <?PHP echo $dateofloss ?>; our office has received your information and will contact you as soon as possible.</p>
<p style=”font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:20px 0 0 200px;”>Sincerely,</p>
<p style=”margin: 10px 0 0 200px;”><img src=”http://beta.XXXXXX.com/img/uniform/briansig.gif” alt=”” /></p>
<p style=”font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:0px 0 0 200px;”>Brian R Miller, priciple</p>
<p style=”font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:200px 0 0 0″>This email has been sent by an automated service</p>
–PHP-alt-<?php echo $random_hash; ?>–
<?PHP

$message = ob_get_clean();

mail($to, $subject, $message, $headers);
?>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@sohguanhDec 07.2010 — Have you try to use other PHP mailer besides the built-in mail function ? In Perl, I notice some mail modules has some problem for some web-based email and it seems to be the mail modules internal implementation that is causing the problem. In the end I switch to another Perl mailer module.

One simple way to check is use the Linux/Unix sendmail program to send the same email to Gmail and see if it works or not. If it works for sendmail but not your PHP mail function then possibly mail function internal implementation is missing out something.
Copy linkTweet thisAlerts:
@jason87Dec 07.2010 — My PHP mail() works fine with my Gmail, maybe it has something to do with the funcions you are using?
×

Success!

Help @cfgcjm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...