I want to customize an php email with some html but I'm struggling with that...
After submit my form i receive the email but happen this
I was following this tutorial
I put the code i used.
$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 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 <xxxx#xxxx>');
}
Here is a simple example I have done .
//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";
Related
I am trying to modify email notification code so that when a condition is met, a variable will change.
Basically, if the last $key_row->keyVal in the loop has any upper or lower letters in the 13 character string, then it will make the server addresss variable equal to server2.domain.com. Else server address variable equals server1.domain.com . Server address variable does not exist yet and won't be used outside this area.
Thank you for any help.
if (isset($_POST['emailcustomer']) && $_POST['emailcustomer'] == "1")
{
// Send email
$to = email_sanitize($row->ordEmail);
$subject = 'Keys';
$message = '
<b>Keys Order</b><br />
Thanks for your recent order. Here are the keys that you ordered: '.$row->ordID.':<br /><br />
';
while ($key_row = $key_query->fetch_object())
{
$message .= 'Username: ' . $key_row->keyVal . ' / Password: ' . $key_row->keyVal . ' / Expiration: ' . strtoupper(date('d-M-Y', strtotime($key_row->keyEnd))) . '<br />';
}
$message .= '<br />
<br />
Server Address: server.domain.com (<---Variable Here)<br />
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $from_name . ' <' . $from_email . '>' . "\r\n";
mail($to, $subject, $message, $headers);
print 'Email sent.';
}
fetch the data first then put in an array
$data_info = array();
while($row=mysql_fetch_assoc($result_main)){
$data_info[]= $row;
}
then you will cal it using this
$z=0;
for($y=1;$y<=$Num_rows_Data;$y++){
$get_bar = $data_info[$z]['name_of_fields'];
$z++;
}
I use a simple section of php in my header to send the contents of a mysqli query (in this case a combination of three queries - 'ORDER' has the shipping details, 'CUSTOMER' contains the email details of the customer, and 'PRODLIST' has a list of products entered into the shopping cart)
I put together the following script, trying to collect the 'ORDER' details, and add a repeating region to add all the records in the 'PRODLIST' query.
It didn't work, and I was wondering if this is even possible, and if not is there a solution that will allow me to send a simple html email with the full details?
Both queries are working by the way, they are listed on screen in the actual web page, but the mail code is not responding, and causing the page not to load.
$to = 'RECIPIENT REMOVED';
$subject = "order from " . $ORDER->getColumnVal("CUSTOMER_NAME");
$headers = "From: " . $CUSTOMER->getColumnVal("EMAIL") . "\r\n";
$headers .= "Reply-To: ". $CUSTOMER->getColumnVal("EMAIL") . "\r\n";
$headers .= "BCC: info#sigwebdesign.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";$from = "<".$CUSTOMER->getColumnVal("EMAIL").">";
$message = '<html><body>';
$message .= '<p>The following order has been received</p>';
$message .= "Delivery Type: " . $ORDER->getColumnVal("DELIVERY_TYPE") . "<br>";
$message .= "<b>Delivery Date: " . $ORDER->getColumnVal("DELIVERY_DATE") . "<br><br><br></b>";
$message .= "Company: " . $ORDER->getColumnVal("CUSTOMER_NAME") . "<br>";
$message .= "Contact: " . $ORDER->getColumnVal("PLACED_BY") . "<br><br>";
$message .= "Address: " . $ORDER->getColumnVal("DELIVERY_ADDRESS") . "<br>";
$message .= "Address: " . $ORDER->getColumnVal("CITY") . "<br>";
$message .= "Address: " . $ORDER->getColumnVal("STATE") . "<br>";
$message .= "Address: " . $$ORDER->getColumnVal("ZIP") . "<br><br><br>";
while(!$PRODLIST->atEnd()) {
$message .= "ITEM: " . $PRODLIST->getColumnVal("GENUS")." ".$PRODLIST->getColumnVal("VARIETY") . "<br>";
$message .= "QTY: " . $PRODLIST->getColumnVal("QUANTITY") . "<br>";
$PRODLIST->moveNext();
}
$PRODLIST->moveFirst();
$message .= "Total Cost: " . $_SESSION['fullcost'] . "<br><br><br>";
$message .= "This price does not include shipping, and applicable taxes. <br> Your order will be processed, and a final confirmation will be sent to you by email or by phone. <br><br>";
$message .= '</html></body>';
mail($to,$subject,$message,$headers);
So I worked it out. I added an extra "$" in the coding, and it threw a whole big spanner in the works.
so the answer (note to self at least) is check check and triple check the code!
All of sudden, my PHP code that sends an email after someone registers on a form stopped working. I'm cracking my head trying to figure out what is going on...
I already tested a little piece of code emailing myself and it works.
I observed the console window in Chrome while the page executes, but it doesn't show any errors.
The code sends me an email with the form info and sends an email to the user's inbox telling that the registration was successful.
// SENDING EMAIL
//To me
$line_break = "\r\n";
$emailSender = "subscriptions#mydomain.com";
$emailTOme = "me#mydomain.com";
$cco = "support#mydomain.com";
$subject= "my subject";
$messageHTML = '
<p>Nome.......: ' . $nome . '</p>
<p>E-mail.......: '.$email . ' </p>
<p>Profissão.......: '. $profissao . ' </p>
<p>Endereço.....: '. $endereco . ', ' . $endereco_num . ' </p>
<p>Complemento.....: '. $complemento . '</p>
<p>Bairro.......: ' . $bairro . ' </p>
<p>CEP..........: '. $cep . ' </p>
<p>Cidade.......: ' . $cidade . ' </p>
<p>UF...........: ' . $uf . ' </p>
<p>Telefone.....: ' . $telefone . ' </p>
<p>Celular......: ' . $celular . ' </p>
<p>Inscrição p/.: ' . $evento . '</p>
<p>Valor da inscrição: <b>R$' . $valor_inscricao . '</b></p>';
$headers = "MIME-Version: 1.1" . $line_break;
$headers .= "Content-type: text/html; charset=iso-8859-1". $line_break;
$headers .= "From: " . $emailSender . $line_break;
$headers .= "Return-Path: " . $emailSender . $line_break;
$headers .= "Bcc: " . $cco . $line_break;
$headers .= "Reply-to: " . $emailSender . $line_break;
mail($emailTOme , $subject, $messageHTML,$headers, $emailSender);
//email for the user
$messageHTMLuser = '
<p> Lorem </p>
<p> Ipsum </b></p>';
$headers2 = "MIME-Version: 1.1" . $line_break;
$headers2 .= "Content-type: text/html; charset=iso-8859-1". $line_break;
$headers2 .= "From: " . $emailSender . $line_break;
$headers2 .= "Return-Path: " . $emailSender . $line_break;
$headers2 .= "Reply-to: " . $emailSender . $line_break;
mail($email, 'We recieved your registration', $messageHTMLuser, $headers2, $emailSender);
The problem is that now only the second mail() function works.
The $email on the second function comes from the previous form.
Try to comment out the "BCC" line.
As the current php mail don't support this option (anymore) - apparantly as a way to avoid bcc-form-spamers..
In order to use advanced email functions, you would probably be better off using PHPMailer (or a similar lib): https://packagist.org/packages/phpmailer/phpmailer
Add this to the start of your script and it should show you your errors (if any) at the top of the page.
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
I have three checkboxes for requesting catalogs. I would like to get value for all three of them in each email.
Here is my HTML:
<input type="checkbox" name="catalog" value="Grower"/> Grower Supply Catalog <br><br>
<input type="checkbox" name="catalog" value="Specialty"/> Specialty Catalog<br><br>
<input type="checkbox" name="catalog" value="Plant"/> Plant Source Catalog
Here is my PHP:
$name = #$_POST["name"];
$email = #$_POST["email"];
$street = #$_POST["street"];
$city = #$_POST["city"];
$state = #$_POST["state"];
$zip = #$_POST["zip"];
$email = #$_POST["email"];
$phone = #$_POST["phone"];
$message = #$_POST["comment"];
$catalog =#$_POST["catalog"];
foreach($_POST['catalog'] as $value) {
$check_msg .= "Checked: $value\n";
}
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
$mailBody = "You have been contacted by $name" . PHP_EOL . PHP_EOL;
$mailBody .= (!empty($company))?'Company: '. PHP_EOL.$company. PHP_EOL . PHP_EOL:'';
$mailBody .= (!empty($quoteType))?'project Type: '. PHP_EOL.$quoteType. PHP_EOL . PHP_EOL:'';
$mailBody .= "Street :" . PHP_EOL;
$mailBody .= $street . PHP_EOL . PHP_EOL;
$mailBody .= "City :" . PHP_EOL;
$mailBody .= $city . PHP_EOL . PHP_EOL;
$mailBody .= "State :" . PHP_EOL;
$mailBody .= $state . PHP_EOL . PHP_EOL;
$mailBody .= "Zip :" . PHP_EOL;
$mailBody .= $zip . PHP_EOL . PHP_EOL;
$mailBody .= "Phone :" . PHP_EOL;
$mailBody .= $phone . PHP_EOL . PHP_EOL;
$mailBody .= $check_msg .= "Catalog : $catalog\n";
$mailBody .= "Message :" . PHP_EOL;
$mailBody .= $message . PHP_EOL . PHP_EOL;
$mailBody .= "You can contact $name via email, $email.";
$mailBody .= (isset($phone) && !empty($phone))?" Or via phone $phone." . PHP_EOL . PHP_EOL:'';
if(mail($to, $subject, $mailBody, $headers)){
echo '<div class="alert alert-success">Success! Your message has been sent.</div>';
}
}
How can I send the checkbox values to email?
Use array syntax for those element names to send those values as an array:
<input type="checkbox" name="catalog[]" value="Grower"/> Grower Supply Catalog <br><br>
<input type="checkbox" name="catalog[]" value="Specialty"/> Specialty Catalog<br><br>
<input type="checkbox" name="catalog[]" value="Plant"/> Plant Source Catalog
I think You Should type properly foreach() method, type in camelCase Like this forEach()
I'm creating a user require form in my site. For this I put some validation on compulsory fields, and when a user fills in the form and presses submit and validation is correct then I receive a email on my email address.
But now I would like all user information in the email, like name, city, budget etc... so what changes do I need to make in my email.php script?
If some fields are not compulsory and the user doesn't fill them in, can they affect my script?
My script is:
<?php
$to = "test#networkers.in";
$subject = "a new requiremnet come!";
$message = "Hi,\n\nyou get a new require";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "Sender-IP: " . $_SERVER["SERVER_ADDR"] . "\r\n";
$headers .= "From: " . stripslashes($name) . " <" . $email . ">" . "\r\n";
$headers .= "Priority: normal" . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
$sent = mail($to, $subject, $message, $headers) ;
if ($sent) {
echo "Your mail was sent successfully";
} else {
echo "We encountered an error sending your mail";
}
?>
and the data I recieve is:
$name = $_POST['fname'].' '.$_POST['lname'];
$email = $_POST['mail'];
$phone = $_POST['ph'];
$country = $_POST['country'];
$pt = $_POST['pt'];
$cwl = $_POST['cwl'];
$dyhyows = $_POST['dyhyows'];
$pb = $_POST['pb'];
$bpd = $_POST['bpd'];
$hdyhau = $_POST['hdyhau'];
You can add fields to the message body by concatenating them like so:
$message = "Hi,\n\nyou get a new require";
$message .= "\n Name: " . $name;
$message .= "\n Email: " . $email;
$message .= "\n Phone: " . $phone;
$message .= "\n Country: " . $country;
$message .= "\n pt: " . $pt;
$message .= "\n cwl: " . $cwl;
$message .= "\n dyhyows: " . $dyhyows;
$message .= "\n pb: " . $pb;
$message .= "\n bpd: " . $bpd;
$message .= "\n hdyhau: " . $hdyhau
Any fields that weren’t filled in by the user will simply be blank.