2017-07-26 26 views
-3

所以,我有一個PHP script,它基本上發送一封電子郵件,當您退訂。代碼很好,所以我輸入到我的PHP,但它只發送它的一部分。 Here是它應該是的JSFiddle。這不是很乾淨,因爲這是一封電子郵件的HTML,但這不是重點。所以我有我的電子郵件代碼,我可以運行它,並看到它的工作完美,並運行電子郵件只是我想要它。我也測試了我的PHP。它向我發送了一封電子郵件,之前我已經對它進行了測試,這讓我知道它確實發送了所要求的內容。這是我的PHP代碼:PHP只發送電子郵件的一部分

<?php 
    $to = '[email protected]'; 

    $subject = 'Sorry To See You Go!'; 

    $headers = "From: [email protected]" . strip_tags($_POST['req-email']) . "\r\n"; 
    $headers .= "Reply-To: [email protected]". strip_tags($_POST['req-email']) . "\r\n"; 
    $headers .= "CC: [email protected]\r\n"; 
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; 

    $message .= '<table align="center" border="0" cellpadding="0" cellspacing="0" class="main-width" width="630" style="border-collapse: collapse; table-layout: fixed; font-family: &quot;Times New Roman&quot;; font-size: medium; width: 630px;"><tbody><tr><td align="center" class="layout" valign="top" style="padding: 15px 5px;"><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed;"><tbody><tr><td align="center" bgcolor="#4C4C4C" class="layout-container-border" valign="top" style="background: rgb(76, 76, 76); padding: 10px;"><table align="center" bgcolor="#4C4C4C" border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><tbody><tr><td align="center" bgcolor="#FFFFFF" class="layout-container" valign="top" style="background: rgb(255, 255, 255); padding: 0px;"><div class=""><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="logo OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-image"><table border="0" cellpadding="0" cellspacing="0" class="editor-image logo-container editor-image-vspace-on" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="center" valign="top" style="padding-bottom: 10px; padding-top: 10px;"><div class="publish-container"><a href="http://html-hub.net16.net/" target="_blank" style="text-decoration-line: underline;"><img alt="" border="0" class="" hspace="0" src="http://files.constantcontact.com/69a6c42a601/8b94df2c-ed2c-40ea-ad5d-12bd5a1f8eab.png" vspace="0" width="197" style="display: block;"></a></div></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-text"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="editor-text editor-text " valign="top" style="-webkit-font-smoothing: antialiased; color: rgb(64, 63, 66); display: block; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; padding: 10px 20px; word-wrap: break-word;"><div></div><div><div align="center" style="text-align: center;">&nbsp;&nbsp;<span style="color: rgb(71, 155, 70); font-size: 24px; font-weight: bold;">Sorry To See You Go!</span></div></div></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-divider"><table border="0" cellpadding="0" cellspacing="0" class="editor-divider" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="center" class="" valign="top"><table class="galileo-ap-content-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; cursor: default; min-width: 100%;"><tbody><tr><td align="center" class="divider-base divider-solid" valign="top" width="100%" style="padding: 9px 0px 10px;"><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; table-layout: fixed; height: 1px; min-width: 95%; width: 570.4px;"><tbody><tr><td align="center" bgcolor="rgb(69, 179, 202)" height="1" style="background: rgb(69, 179, 202); border-bottom-style: none; height: 1px; line-height: 1px; padding-bottom: 4px;"><img alt="" border="0" height="1" hspace="0" src="https://imgssl.constantcontact.com/letters/images/1101116784221/S.gif" vspace="0" width="5" style="display: block; height: 1px; width: 5px;"></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-text"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="editor-text editor-text " valign="top" style="-webkit-font-smoothing: antialiased; color: rgb(64, 63, 66); display: block; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; padding: 10px 20px; word-wrap: break-word;"><div></div><div><div align="center" style="text-align: center;"><div>&nbsp;<span style="font-size: 18px;">At CyanCoding, we try out best to present our users with easy accessibility, fun programs, and a quality website. We think you made a mistake by unsubscribing, but you are the boss! You will no longer receive emails stating new programs, updates, or other news.</span><br></div><br></div></div></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-divider"><table border="0" cellpadding="0" cellspacing="0" class="editor-divider" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="center" class="" valign="top"><table class="galileo-ap-content-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; cursor: default; min-width: 100%;"><tbody><tr><td align="center" class="divider-base divider-solid" valign="top" width="100%" style="padding: 9px 0px 10px;"><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; table-layout: fixed; height: 1px; min-width: 95%; width: 570.4px;"><tbody><tr><td align="center" bgcolor="rgb(69, 179, 202)" height="1" style="background: rgb(69, 179, 202); border-bottom-style: none; height: 1px; line-height: 1px; padding-bottom: 4px;"><img alt="" border="0" height="1" hspace="0" src="https://imgssl.constantcontact.com/letters/images/1101116784221/S.gif" vspace="0" width="5" style="display: block; height: 1px; width: 5px;"></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-text"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="editor-text editor-text " valign="top" style="-webkit-font-smoothing: antialiased; color: rgb(64, 63, 66); display: block; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; padding: 10px 20px; word-wrap: break-word;"><div></div><div><div align="center" style="text-align: center;"><span style="font-size: 14px;">If you believe this to be a mistake, please click the button below.</span></div></div></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-button"><table border="0" cellpadding="0" cellspacing="0" class="editor-button" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%; width: 600.8px;"><tbody><tr><td class="editor-button-container editor-button-container " style="color: rgb(255, 255, 255); font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 14px; padding: 10px 20px;"><table class="galileo-ap-content-editor" style="border-collapse: collapse; table-layout: fixed; min-width: 100%; width: 560.8px;"><tbody><tr><td align="center" class="MainTextFullWidthTD" valign="top" style="font-family: Arial, Verdana, Helvetica, sans-serif; padding: 0px;"><table bgcolor="#4C4C4C" border="0" cellpadding="0" cellspacing="0" class="" style="border-collapse: collapse; table-layout: fixed; background: rgb(76, 76, 76); border-spacing: 0px; border: none; min-width: initial; padding: 0px; width: initial;"><tbody><tr><td align="center" class="MainTextFullWidthTD" valign="top" style="font-family: Arial, Verdana, Helvetica, sans-serif; padding: 9px 15px 10px;"><div class="MainTextFullWidth" style="-webkit-font-smoothing: antialiased;"><a href="http://cyancoding.net16.net/subscribe.html" target="_blank" style="color: rgb(255, 255, 255);">Subscribe</a></div></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" bgcolor="#4C4C4C" class="about OneColumnMobile column" valign="top" width="100%" style="background: rgb(76, 76, 76);"><div class="gl-contains-text"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="editor-text about-text" valign="top" style="-webkit-font-smoothing: antialiased; color: rgb(255, 255, 255); display: block; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; padding: 10px 20px; text-align: center; word-wrap: break-word;"><div></div><div><a href="mailto:[email protected]" target="_blank" style="text-decoration-line: underline; color: rgb(106, 194, 213);">Email</a>&nbsp;|&nbsp;<a href="http://cyancoding.net16.net/" target="_blank" style="text-decoration-line: underline; color: rgb(106, 194, 213);">Website</a>&nbsp;|&nbsp;<a href="http://cyancoding.net16.net/subscribe.html" target="_blank" style="text-decoration-line: underline; color: rgb(106, 194, 213);">Subscribe</a></div></td></tr></tbody></table></div></td></tr></tbody></table></div></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table><span></span>'; 


    mail($to, $subject, $message, $headers); 
?> 

PS我填寫的電子郵件地址,它說[email protected]

所以,如果你運行它,這裏是結果的電子郵件:

Email error

這是不對的了!正如我們所看到的,這遠離我們前面看到的JSFiddle

我想讓PHP發送電子郵件,就像HTML的顯示方式一樣。這裏是一個片段的電子郵件的代碼,如果有幫助:

<table align="center" border="0" cellpadding="0" cellspacing="0" class="main-width" width="630" style="border-collapse: collapse; table-layout: fixed; font-family: &quot;Times New Roman&quot;; font-size: medium; width: 630px;"><tbody><tr><td align="center" class="layout" valign="top" style="padding: 15px 5px;"><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed;"><tbody><tr><td align="center" bgcolor="#4C4C4C" class="layout-container-border" valign="top" style="background: rgb(76, 76, 76); padding: 10px;"><table align="center" bgcolor="#4C4C4C" border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><tbody><tr><td align="center" bgcolor="#FFFFFF" class="layout-container" valign="top" style="background: rgb(255, 255, 255); padding: 0px;"><div class=""><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="logo OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-image"><table border="0" cellpadding="0" cellspacing="0" class="editor-image logo-container editor-image-vspace-on" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="center" valign="top" style="padding-bottom: 10px; padding-top: 10px;"><div class="publish-container"><a href="http://html-hub.net16.net/" target="_blank" style="text-decoration-line: underline;"><img alt="" border="0" class="" hspace="0" src="http://files.constantcontact.com/69a6c42a601/8b94df2c-ed2c-40ea-ad5d-12bd5a1f8eab.png" vspace="0" width="197" style="display: block;"></a></div></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-text"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="editor-text editor-text " valign="top" style="-webkit-font-smoothing: antialiased; color: rgb(64, 63, 66); display: block; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; padding: 10px 20px; word-wrap: break-word;"><div></div><div><div align="center" style="text-align: center;">&nbsp;&nbsp;<span style="color: rgb(71, 155, 70); font-size: 24px; font-weight: bold;">Sorry To See You Go!</span></div></div></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-divider"><table border="0" cellpadding="0" cellspacing="0" class="editor-divider" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="center" class="" valign="top"><table class="galileo-ap-content-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; cursor: default; min-width: 100%;"><tbody><tr><td align="center" class="divider-base divider-solid" valign="top" width="100%" style="padding: 9px 0px 10px;"><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; table-layout: fixed; height: 1px; min-width: 95%; width: 570.4px;"><tbody><tr><td align="center" bgcolor="rgb(69, 179, 202)" height="1" style="background: rgb(69, 179, 202); border-bottom-style: none; height: 1px; line-height: 1px; padding-bottom: 4px;"><img alt="" border="0" height="1" hspace="0" src="https://imgssl.constantcontact.com/letters/images/1101116784221/S.gif" vspace="0" width="5" style="display: block; height: 1px; width: 5px;"></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-text"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="editor-text editor-text " valign="top" style="-webkit-font-smoothing: antialiased; color: rgb(64, 63, 66); display: block; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; padding: 10px 20px; word-wrap: break-word;"><div></div><div><div align="center" style="text-align: center;"><div>&nbsp;<span style="font-size: 18px;">At CyanCoding, we try out best to present our users with easy accessibility, fun programs, and a quality website. We think you made a mistake by unsubscribing, but you are the boss! You will no longer receive emails stating new programs, updates, or other news.</span><br></div><br></div></div></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-divider"><table border="0" cellpadding="0" cellspacing="0" class="editor-divider" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="center" class="" valign="top"><table class="galileo-ap-content-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; cursor: default; min-width: 100%;"><tbody><tr><td align="center" class="divider-base divider-solid" valign="top" width="100%" style="padding: 9px 0px 10px;"><table align="center" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; table-layout: fixed; height: 1px; min-width: 95%; width: 570.4px;"><tbody><tr><td align="center" bgcolor="rgb(69, 179, 202)" height="1" style="background: rgb(69, 179, 202); border-bottom-style: none; height: 1px; line-height: 1px; padding-bottom: 4px;"><img alt="" border="0" height="1" hspace="0" src="https://imgssl.constantcontact.com/letters/images/1101116784221/S.gif" vspace="0" width="5" style="display: block; height: 1px; width: 5px;"></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-text"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="editor-text editor-text " valign="top" style="-webkit-font-smoothing: antialiased; color: rgb(64, 63, 66); display: block; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; padding: 10px 20px; word-wrap: break-word;"><div></div><div><div align="center" style="text-align: center;"><span style="font-size: 14px;">If you believe this to be a mistake, please click the button below.</span></div></div></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="" class="OneColumnMobile column" valign="top" width="100%"><div class="gl-contains-button"><table border="0" cellpadding="0" cellspacing="0" class="editor-button" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%; width: 600.8px;"><tbody><tr><td class="editor-button-container editor-button-container " style="color: rgb(255, 255, 255); font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 14px; padding: 10px 20px;"><table class="galileo-ap-content-editor" style="border-collapse: collapse; table-layout: fixed; min-width: 100%; width: 560.8px;"><tbody><tr><td align="center" class="MainTextFullWidthTD" valign="top" style="font-family: Arial, Verdana, Helvetica, sans-serif; padding: 0px;"><table bgcolor="#4C4C4C" border="0" cellpadding="0" cellspacing="0" class="" style="border-collapse: collapse; table-layout: fixed; background: rgb(76, 76, 76); border-spacing: 0px; border: none; min-width: initial; padding: 0px; width: initial;"><tbody><tr><td align="center" class="MainTextFullWidthTD" valign="top" style="font-family: Arial, Verdana, Helvetica, sans-serif; padding: 9px 15px 10px;"><div class="MainTextFullWidth" style="-webkit-font-smoothing: antialiased;"><a href="http://cyancoding.net16.net/subscribe.html" target="_blank" style="color: rgb(255, 255, 255);">Subscribe</a></div></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></td></tr></tbody></table><table border="0" cellpadding="0" cellspacing="0" class="galileo-ap-layout-editor" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" bgcolor="#4C4C4C" class="about OneColumnMobile column" valign="top" width="100%" style="background: rgb(76, 76, 76);"><div class="gl-contains-text"><table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; table-layout: fixed; min-width: 100%;"><tbody><tr><td align="left" class="editor-text about-text" valign="top" style="-webkit-font-smoothing: antialiased; color: rgb(255, 255, 255); display: block; font-family: Arial, Verdana, Helvetica, sans-serif; font-size: 12px; padding: 10px 20px; text-align: center; word-wrap: break-word;"><div></div><div><a href="mailto:[email protected]" target="_blank" style="text-decoration-line: underline; color: rgb(106, 194, 213);">Email</a>&nbsp;|&nbsp;<a href="http://cyancoding.net16.net/" target="_blank" style="text-decoration-line: underline; color: rgb(106, 194, 213);">Website</a>&nbsp;|&nbsp;<a href="http://cyancoding.net16.net/subscribe.html" target="_blank" style="text-decoration-line: underline; color: rgb(106, 194, 213);">Subscribe</a></div></td></tr></tbody></table></div></td></tr></tbody></table></div></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table><span></span>

編輯:事實證明,這個問題本來就不是我的代碼,但它實際上是我的整個文件並且它並未完全執行,因爲文件中的其他代碼在其中存在錯誤。

+0

開始刪除這個'$ message。='中的點,因爲在此之前我沒有看到任何其他聲明。 –

+0

它呈現的方式取決於使用的電子郵件客戶端。您收到的是什麼內容(例如Gmail,Outlook)? – Andy

+0

我也會說 - 添加一個「Content-Length」標頭。 – t1gor

回答

0

弗雷德都表示,除去$message .=點,我問

這裏是要附加到這裏$message .=,因爲它代表你有其他$消息:

注意:未定義的變量:因此在第12行上

消息改變$message .= "...";

$message = "..." 

然後你會得到的結果

enter image description here

0

嘗試添加 「內容傳輸編碼:BASE64 \ r \ n」 參數進行刪除字符限制

mail($to, $subject, chunk_split(base64_encode($message), "Content-Transfer-Encoding: base64\r\n");