Dmitry Makovetskiyd
Dmitry Makovetskiyd

Reputation: 7053

sending email fails.. with php function

I have got email method that works:

   <?php
     $to = "[email protected]";
     $subject = "Hi!";
    $body=email_template('http://zzzzedapps.com/app_dl.php?app_id=34', $app_pic, $app_name);
    echo $body;
     $headers = 'From: [email protected]' . "\r\n" .
        'Reply-To: [email protected]' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
     if (mail($to, $subject, $body,$headers)) {
       echo("<p>Message successfully sent!</p>");
      } else {
       echo("<p>Message delivery failed...</p>");
      }
     ?>

but when I use this function to set the body variable..:

   function email_template($app_link, $img_link, $app_name){
       $message='
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            </head>
            <body>

      <div id="pic" style="position:relative; text-align:center; margin:0px auto;width:320px; height: 480px;">
       <a href="http://zzzzedapps.com">  
       <div id="logo" style="position:absolute; width:130px; height:35px; z-index:99999;top:5;">
       </div>
       </a>
        <div id="clickHere" style=" position:absolute;width:320px;height:50px;z-index:99999;top:60px;text-align: center;">
            <span id="clickHereText" style="font-size:140%; color:white;"> <a href="'.$app_link.'" style="color:yellow">Click Here</a> to Download<br/>
                 your phonemate app
                 </span>
        </div>

        <div id="appImg" style="position:absolute;width:50px; height:50px;z-index:99999; left:50px;top:210px;">
            <img src="http://zzzzedapps.com/'.$img_link.'" width="53px" height="53px"/>
        </div>
        <div id="appLabel" style="position:absolute; width:50px; height:10px; z-index:99999; text-align: center; left:50px; top:260px;">
            <span style="color:white; font-size: 50%;">'.$app_name.'</span>
        </div>

        <div id="downloadLink" style="position:absolute; width:320px; height:30px;  z-index:99999; bottom:0px; text-align: center;">
            <a href="'.$app_link.'" style="color:yellow">Download our app on zzzzedApps.com</a>
        </div>
       <img src="http://zzzzedapps.com/email/images/zzzzedAppEmail.jpg"/>
    </div>
       </body>
   </html>';

  return $message;
}

it fails to deliver the email.

This fails:

$body=email_template('http://zzzzedapps.com/app_dl.php?app_id=34', $app_pic, $app_name);

although the body is echoed successfully?

where do I have the bug.. and how do I overcome it?

Upvotes: 0

Views: 106

Answers (1)

jeroen
jeroen

Reputation: 91744

You are using php's mail function to send an html mail, check the manual, specifically:

// To send HTML mail, the Content-type header must be set

in example #4.

I'm also pretty sure you need to get rid of the doctype.

Upvotes: 1

Related Questions