2015-06-16 23 views
-1

我想自定義的PHP電子郵件與一些HTML,但我與掙扎......自定義的HTML PHP的郵件

提交我的表格後,我收到的電子郵件,但發生this

我正在關注這個tutorial

我把我使用的代碼。

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Alright, lets send the email already! 
if (empty($errorString)) { 

    $mailbody .= '<html><body>'; 
    $mailbody .= '<img src="//http://xxxx/xxxxx/wp-content/uploads/2015/06/email.jpg" alt="Website Change Request" />'; 
    $mailbody .= '<table rules="all" style="border-color: #666;" cellpadding="10">'; 

    $mailbody .= __('Nome:', 'ci_theme') . ' ' . $clientname . "\n"; 
    $mailbody .= __('Email:', 'ci_theme') . ' ' . $email . "\n"; 
    $mailbody .= __('Chegada:', 'ci_theme') . ' ' . $arrive . "\n"; 
    $mailbody .= __('Saída:', 'ci_theme') . ' ' . $depart . "\n"; 
    $mailbody .= __('Adultos:', 'ci_theme') . ' ' . $guests . "\n"; 
    $mailbody .= __('Crianças:', 'ci_theme') . ' ' . $children . "\n"; 
    $mailbody .= __('Quarto:', 'ci_theme') . ' ' . $room->post_title . "\n"; 
    $mailbody .= __('Mensagem:', 'ci_theme') . ' ' . $message . "\n"; 
    $mailbody .= __('Hora do Check-in (hh:mm):', 'ci_theme') . ' ' . $timeguest . "\n"; 
    $mailbody .= __('Contacto:', 'ci_theme') . ' ' . $contactguest . "\n"; 
    $mailbody .= __('Autorização:', 'ci_theme') . ' ' . $autorizo . "\n"; 
    $mailbody .= __('Cama Extra:', 'ci_theme') . ' ' . $camaextra . "\n"; 
    $mailbody .= "</table>"; 
    $mailbody .= "</body></html>"; 

    mail($to, $mailbody, $headers); 

    // If you want to receive the email using the address of the sender, comment the next $emailSent = ... line 
    // and uncomment the one after it. 
    // Keep in mind the following comment from the wp_mail() function source: 
    /* If we don't have an email from the input headers default to [email protected]$sitename 
    * Some hosts will block outgoing mail from this address if it doesn't exist but 
    * there's no easy alternative. Defaulting to admin_email might appear to be another 
    * option but some hosts may refuse to relay mail from an unknown domain. See 
    * http://trac.wordpress.org/ticket/5007. 
    */ 
    //$emailSent = wp_mail(ci_setting('booking_form_email'), get_option('blogname').' - '. __('Booking form', 'ci_theme'), $mailbody); 
    $emailSent = wp_mail(ci_setting('booking_form_email'), get_option('blogname').' - '. __('Formulário de Reserva','theme-text-domain', 'ci_theme'), $mailbody, 'From: "'.$clientname.'" <'.$email.'>'); 
    $emailSent2 = wp_mail($email, __('Booking Inquiry','theme-text-domain', 'ci_theme'), __('Thank you so much for your interest in Hotel Aveiro Center! We will get back to you within 24 hours to answer your request.','theme-text-domain','ci_theme'),'From: Hotel Aveiro Center <[email protected]>'); 

} 
+3

自定義郵件??你已經擁有了自己的'mailbody'。你想在郵件中改變什麼? –

+0

首先,問題是什麼? 「我很掙扎」並沒有給我們太多的工作機會。此外,您正在將值附加到'$ mailbody'變量,但在此代碼段中您尚未定義它。您需要先定義它('$ mailbody = NULL;'),然後才能追加。 – cameronjonesweb

+0

感謝您的建議。即時通訊新的與PHP。我想這樣做https://css-tricks.com/wp-content/csstricks-uploads/before-and-after.png(之後) –

回答

0

這是我做的一個簡單的例子。

//build email to be sent 
    $to = $email; 
    $subject = $site_url; 
    $subject .= ": Activate Your Account"; 

    $message = " 
    <html> 
    <head> 
    <title>Account Activation</title> 
    </head> 
    <body> 
    <h3>Account Activation</h3> 
    <p>Dear ".$user.", thank you for registering at ".$site_url.".</p> 
    <p>Please click on the link below to activate your account:</p> 
    <a href='".$site_url."/confirm_user_reg.php?activation_key=".$activation_key."'>http://www.".$site_url."</a>. 
    <p>If the above link does not work, copy and paste the below URL to your browser's address bar:</p> 
    <p><i>http://www.".$site_url."/confirm_user_reg.php?activation_key=".$activation_key."</i></p><br/> 
    <p>If you did not initiate this request, simply disregard this email, and we're sorry for bothering you.</p> 
    <br/><br/> 
    <p>Sincerely,</p> 
    <p>The ".$site_url." Team.</p> 
    </body> 
    </html> 
    "; 

    // To send HTML mail, the Content-type header must be set 
    $headers = "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";