I needed to edit the body of an email (after completing the form, an email is sent). But I'm not able to integrate my HTML code with PHP.
I will send a printscreen of what is happening.
WhatIwantedwassomethinglikethis- link
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]>');
}
}
?>
Am I putting the code well?
/ 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 was able to remove - WordPress -. leaving only the sender's name.
changing the code
$headersWp .= "From: $clientname" . "\r\n";
To:
$headersWp .= "From: $clientname, <$email>" . "\r\n";
The question of characters with accents and cedillas is just missing