1
He needed to edit the body of an email (after completing the form, an email is sent). But I can’t integrate my HTML code with PHP.
I’ll send you a printscreen of what’s happening.
What I wanted was something like this - https://css-tricks.com/wp-content/csstricks-uploads/before-and-after.png
CODE:
<?php
// Sanitize data, or initialize if they don't exist.
$clientname = isset( $_POST['ci_name'] ) ? esc_html( trim( $_POST['ci_name'] ) ) : '';
$email = isset( $_POST['ci_email'] ) ? esc_html( trim( $_POST['ci_email'] ) ) : '';
$arrive = isset( $_POST['arrive'] ) ? esc_html( trim( $_POST['arrive'] ) ) : '';
$depart = isset( $_POST['depart'] ) ? esc_html( trim( $_POST['depart'] ) ) : '';
$guests = isset( $_POST['adults'] ) ? intval( $_POST['adults'] ) : '0';
$children = isset( $_POST['children'] ) ? intval( $_POST['children'] ) : '0';
$message = isset( $_POST['ci_comments'] ) ? sanitize_text_field( stripslashes( $_POST['ci_comments'] ) ) : '';
$timeguest = isset( $_POST['ci_timeguest'] ) ? esc_html(trim($_POST['ci_timeguest'])) : '';
$contactguest = isset( $_POST['ci_contactguest'] ) ? esc_html(trim($_POST['ci_contactguest'])) : '';
$autorizo = isset( $_POST['autorizo'] ) ? 'Autorizo o uso do email.' : 'Não autorizo o uso do email.';
$camaextra = isset( $_POST['camaextra'] ) ? 'Necessito de uma cama extra.' : 'Não necessito de uma cama extra.';
// Message is optional, so, no check.
// 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";
// Alright, lets send the email already!
if ( empty( $errorString ) ) {
$mailbody .= '<html><body>';
$mailbody .= '<img src="/wp-content/uploads/2015/06/email.jpg" />';
$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 wordpress@$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]>');
}
}
?>
I’m putting the code right?
/ 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";
// Alright, lets send the email already!
if ( empty( $errorString ) ) {
$mailbody .= '<html><body>';
$mailbody .= '<img src="http://invisual.pt/hotelaveirocenter/wp-content/uploads/2015/06/email.jpg'. $_SERVER['invisual.pt'] . 'http://invisual.pt/hotelaveirocenter/wp-content/uploads/2015/06/email.jpg" />';
$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
);
// NOVO header adicionado no wp_mail
$headersWp = 'MIME-Version: 1.0' . "\r\n";
$headersWp .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersWp .= "From: $clientname" . "\r\n";
$emailSent = wp_mail(
ci_setting('booking_form_email'),
get_option('blogname').' - '. __('Formulário de Reserva','theme-text-domain','ci_theme'),
$mailbody,
$headersWp);
$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]>');
}
}
I managed to remove - Wordpress - . getting only the Sender Name.
changing the code
$headersWp .= "From: $clientname" . "\r\n";
for:
$headersWp .= "From: $clientname, <$email>" . "\r\n";
Only the question of accented and cedile characters is missing
All right my friend? We at Sopt obviously want to help you, but the way you described it makes it a little difficult. Edit your question and try to elaborate more on what you’re trying to do, what errors are returned, how it should work and what you’re getting, but not something like, "can help me solve/do this," without us knowing what "this" is. The more details the better. Thanks in advance.
– Patrick Maciel
Good afternoon, thanks for the tips. I’m new at this. What he basically wanted was to edit the body of the email sent after completing the form on the site. I’ve put that code above demonstrated, but I’m not getting the intended.
– Ricardo Rafael Rodrigues
Just one question before I post my answer: is the printscreen relative to what you’re getting in your email? Using what? Gmail? Yahoo? Some e-mail of its own?
– Patrick Maciel
Yes the printscreen is relative to what I am receiving in my email. I am using my own email. ([email protected]) And I’m using roudcube Webmail to read the emails
– Ricardo Rafael Rodrigues