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++;
}
Related
I am trying to send emails to a team and some invited individuals to indicate their assigned cooperation. However, only the first recipient (the team) in the $to seems to be receiving an email. The invited individuals do not receive any emails. Can anyone tell what I did wrong?
<?php
/* Template Name: send emails */
include_once ('important.php');
function get_emails($campus) {
global $mydb;
$individuals = array();
$individuals = $mydb->get_results("SELECT * FROM individuals WHERE campus = '$campus'");
return array_map(function($e) {
return $e->individual_email; }, $individuals);
}
$team_email = 'teamA#gmail.com';
$campus = 'NY';
$individuals = get_emails($campus);
$to = $team_email. ', ' .implode(', ', $individuals);
$subject = 'Team invitation from ' . $team_email. '!';
$message = 'Hello everyone, you are now working together';
send_email($message, $subject, $to);
function send_email($message, $subject, $to, $from='admin#gmail.com', $from_name='Admin Team Creator') { $message = '';
$message .= '<html>';
$message .= '<body>';
$message .= $msg;
$message .= '-<br/>';
$message .= '<font face="tahoma, sans-serif" color="#0eafd6"><b>The Admin Team Creator</b></font><br/>';
$message .= '</body>'; $message .= '</html>';
$headers = ''; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: ' . $from . ' <' . $from_name . '>' . "\r\n" . 'Reply-To: ' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
return mail($to, $subject, $message, $headers, '-f ' . $from); }
?>
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);
// Subject of your email
$subject = $_REQUEST['subject'] . ' - Personal website contact form submittion.';
// Recipient's E-mail
$to = 'recipient#domain.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Sender's E-mail
$headers .= "From: Contact Form (Domain.com) <no-reply#domain.com>";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= 'Email: ' . $_REQUEST['email'] . "<br>";
$message .= 'Message: ' . $_REQUEST['message'] . "<br>";
if (#mail($to, $subject, $message, $headers)) {
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
} else {
// Transfer the value 'failed' to ajax function for showing error message.
echo 'failed';
}
How do I put reply-to header here?
Reply-to email should be the email that person enters while filling up the form, I don't know PHP can anyone help me out? thanks
<?php
$subject = $_REQUEST['subject'] . ' - Personal website contact form submittion.'; // Subject of your email
$to = 'recipient#domain.com'; //Recipient's E-mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Contact Form (Domain.com) <no-reply#domain.com>\r\n"; // Sender's E-mail
$headers .= "Reply-To: ".$_REQUEST['email']."<". $_REQUEST['email'].">\r\n" .
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= 'Email: ' . $_REQUEST['email'] . "<br>";
$message .= 'Message: ' . $_REQUEST['message'] . "<br>";
if (#mail($to, $subject, $message, $headers))
{
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
}
else
{
// Transfer the value 'failed' to ajax function for showing error message.
echo 'failed';
}
?>
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";
The below code is designed to send an email when a sale has been made. The body of the email contains information like the customers name, their email address etc. All I'd like to do is add a line break to each of the fields within the final output of the email. I've tried a simple HTML line break and /n and /r which didnt work....any ideas? Thanks!
<?php
//Enter email to receive purchase alerts
///////////////////////////////////////////
$alert_email = 'sales#my-domain.com';
///////////////////////////////////////////
$username = $_POST['username'];
$password = $_POST['password'];
$to = $alert_email;
$subject = 'Sale! = ' .$course;
$message = $name. ' '. $email. ' '. $username. ' '. $password;
$headers = 'From: sales#my-domain.com' . "\r\n" .
'Reply-To: hi#my-domain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
The line that needs to be changed I am sure is this one (and line breaks inserted somewhere here:
$message = $name. ' '. $email. ' '. $username. ' '. $password;
Thanks!
Send a HTML content by applying header Content-type:text/html
$to = $alert_email;
$subject = 'Sale! = ' .$course;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <sales#my-domain.com>' . "\r\n";
$headers .= 'Reply-To: hi#my-domain.com' . "\r\n";
$message = $name. '<br /> '. $email. '<br /> '. $username. '<br /> '. $password;
mail($to, $subject, $message, $headers);
\n should work. Be sure to use a \ instead of a forward slash.