我正在处理一个将Html新闻/ Eflyer发送给订阅者的新闻表单。 我正在使用HTML和内联CSS,而没有HTML,则正在接收电子邮件,但是当我包含HTML时,则没有接收到电子邮件。我不明白我在做什么错。我的代码位于Godaddy服务器上。
我的代码如下。
index.php
<form method="POST" class="newsletter-form">
<input type="email" name="subsemail" id="subsemail" placeholder="Enter your email" required>
<button type="submit" name="newsletter-submit" id="newsletter-submit">
Submit</button>
</form>
script.js
$(document).ready(function() {
$("#newsletter-submit").click(function(e) {
var proceed = true;
if(proceed) //everything looks good! proceed...
{
//data to be sent to server
var m_data = new FormData();
m_data.append( 'subsemail', $('#subsemail').val());
//instead of $.post() we are using $.ajax()
//that's because $.ajax() has more options and flexibly.
$.ajax({
url: 'newsletter.php',
data: m_data,
processData: false,
contentType: false,
type: 'POST',
dataType:'json',
success: function(response){
//load json data from server and output message
if(response.type == 'error'){ //load json data from server and output message
output = '<div class="error">'+response.text+'</div>';
}else{
output = '<div class="success">'+response.text+'</div>';
}
$("#response").hide().html(output).slideDown();
}
});
}
});
});
newsletter.php
<?php
//check if its an ajax request, exit if not
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
$output = json_encode(array( //create JSON data
'type'=>'error',
'text' => 'Sorry Request must be Ajax POST'
));
die($output); //exit script outputting json data
}
$newline = "\r\n";
$mailto = $_POST['subsemail'];
$subject = 'Newsletter Delta Advertising & Publicity L.L.C';
$message = '<html>
<body bgcolor="#e0e0e0" width="100%" style="margin: 0 !important;
padding: 0 !important;
height: 100% !important;
font-family: Segoe, Segoe UI, DejaVu Sans, Trebuchet MS, Verdana, sans-serif;
width: 100% !important;">
<table bgcolor="#e0e0e0" cellpadding="0" cellspacing="0" border="0" height="100%" width="100%" style="border-collapse:collapse;">
<tr>
<td><center style="width: 100%;">
<div style="display:none;font-size:1px;line-height:1px;max-height:0px;max-width:0px;opacity:0;overflow:hidden;mso-hide:all;font-family: sans-serif;"> (Optional) This text will appear in the inbox preview, but not the email body. </div>
<table align="center" width="600" class="email-container">
<tr>
<td style="padding: 20px 0; text-align: center"><a href="https://www.delta-adv.com/others/delta-new/"><img src="images/deltalogo.png" width="100" height="89" alt="alt_text" border="0"></a></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#ffffff" width="600" class="email-container">
<tr>
<td class="full-width-image"><img src="images/banner.png" width="600" alt="alt_text" border="0" align="center" style="width: 100%; max-width: 600px; height: auto;"></td>
</tr>
<tr style="background-color: #336092;">
<td style="padding: 40px; text-align: center; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #FFFFFF;;"><p>We are Delta Advertising & Publicity LLC located in Sharjah U.A.E, we have completed the journey of 10 years of success and perfect services delivery.</p>
<p>Delta Advertising provides best services and products which merge several fields of technologies that distinguishes Delta Advertising among all other companies.</p>
<br>
<br>
<table cellspacing="0" cellpadding="0" border="0" align="center" style="margin: auto">
<tr>
<td style="border-radius: 3px; background: #222222; text-align: center; transition: all 100ms ease-in;">
<a href="https://www.delta-adv.com/others/delta-new/about-us.php" style="background: #222222; border: 15px solid #222222; padding: 0 10px;color: #ffffff; font-family: sans-serif; font-size: 13px; line-height: 1.1; text-align: center; text-decoration: none; display: block; border-radius: 3px; font-weight: bold;" target="_blank">
<!--[if mso]> <![endif]-->Read More<!--[if mso]> <![endif]-->
</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="middle" style="text-align: center;background-color: #477ab2; background-position: center center !important; background-size: cover !important;"><!--[if gte mso 9]>
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="width:600px;height:175px; background-position: center center !important;">
<v:fill type="tile" src="assets/Responsive/Image_600x230.png" color="#222222" />
<v:textbox inset="0,0,0,0">
<tr>
<td dir="ltr" align="center" valign="top" width="100%" style="padding: 10px;"><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="196" class="stack-column-center"><table align="center" border="0" cellpadding="0" cellspacing="0" width="95%">
<tr>
<td dir="ltr" valign="top" style="padding: 0 10px;"><img src="images/Social Media.jpg" width="170" alt="alt_text" border="0" class="center-on-narrow"></td>
</tr>
</table></td>
<td width="384" class="stack-column-center"><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td dir="ltr" valign="top" style="font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #555555; padding: 10px; text-align: left;" class="center-on-narrow"><strong>Socical Media Management: <br>
</strong>Delta Advertising also offers social media services and search engine services. Delta Advertising manages social media networks such as Twitter, Facebook, LinkedIn and Instagram...<br>
<table cellspacing="0" cellpadding="0" border="0" class="center-on-narrow" style="float:left;">
<tr>
<td style="border-radius: 3px; background: #222222; text-align: center;" class="button-td"><a href="http://www.delta-adv.com/others/delta-new/products.php" style="background: #222222; border: 15px solid #222222; padding: 0 10px;color: #ffffff; font-family: sans-serif; font-size: 13px; line-height: 1.1; text-align: center; text-decoration: none; display: block; border-radius: 3px; font-weight: bold;" class="button-a" target="_blank">
</a></td>
</tr>
</table>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</center></td>
</tr>
</table>
</body>
</html>
';
$eol = "\r\n";
// main header (multipart mandatory)
$headers = "From: Delta Advertising Newsletter <info@delta-adv.com>". $eol;
$headers .= "MIME-Version: 1.0". "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8". "\r\n";
//SEND Mail
if (mail($mailto, $subject, $message, $headers)) {
echo "Email has been sent! Thank you for subscribe Delta Advertising Newsletter"; // or use booleans here
} else {
echo "ERROR! Mail has not been sent";
print_r( error_get_last() );
}