I am trying to send an email for multiple addresses that are retrieved from db
while($row = mysql_fetch_assoc($qry9)) {
$email=$row["email"];
$subject = "Testing";
$headers = "From: test#gmail.com \r\n";
$message='New Event Registered';
mail($email,$subject,$message,$headers);
}
In this given like $email="nandha181#gmail.com" is working properly but email from database is not working .I am also checking the email from the database query works correctly.
Related
Im trying to get an email to send from my php page to an email address that is set.
The email is being sent and received at the expected email address. But the contents within the email are not as expected. I got the code from watching a tutorial on youtube.
However when looking at the email is displays exactly as the code below, doesn't give me the values behind the variables e.g $name shows up in the email as $name
Any ideas?
The code im using is;
<?php
require_once 'header.php';
$to = 'emailaddress ';
$subject = 'CSG';
$name = $_POST['name'];
$email = $_POST['emailaddress'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi $name, You have recently requested a notification of your password on the Coleg Sir Gar Loan Syste site.
From $name
EMAIL;
$header = '$email';
if ($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Email Sent';
}
?>
Firstly, variables do not get parsed inside single quotes, that's why you're seeing $email rather than the email itself inside the email body.
So change $header = '$email'; to either $header = "$email"; or remove the quotes entirely.
I.e.: $header = $email;
Then the header is failing you. It expects to be a From: (email address) - The "From" in your mail will come back as your server's name rather than the (intended) email address from the person sending it.
Consult the manual:
http://php.net/manual/en/function.mail.php
Sidenote about your heredoc.
Even though mail is going out, you still have a trailing space in your opening identifier:
$body = <<<EMAIL
and that may throw a Parse error: syntax error, unexpected '<<' (T_SL) error.
Error reporting http://php.net/manual/en/function.error-reporting.php
Testing this came back as:
email#example.com
Hi Fred, You have recently requested a notification of your password on the Coleg Sir Gar Loan Syste site.
From Fred
and the "From:" as default#cpanel.example.com rather than whoever#example_mailer.xxx.
As noted in comments by dieend, you can try bracing the variables {$var}, however with or without them, produced the same results for me.
If that still doesn't work, then it may be caused by the trailing space in your opening identifier; you need to remove it.
Copy/paste exactly as shown:
$body = <<< EMAIL
Hi {$name}, You have recently requested a notification of your password on the Coleg Sir Gar Loan Syste site.
From {$name} - {$email}
EMAIL;
$header = "From:" . $email; // Now you have a valid From
if ($_POST){
mail($to, $subject, $body, $header);
echo $feedback = 'Email Sent';
}
Final notes:
If that still doesn't solve the question, then I for one am unable to reproduce.
I have created a registration and after successful registration user get a email about login details(this happens when user clicks submit button).But i have stuck with a sending another email automatically to the same user after 5 minutes and after 20 days user have registered.in the mysql database registration time saved as Time_created.(timestamp).[2016-04-26 10:25:30].what is the possible way to do this.
Here is my code to send email from form this works correctly.
$r = $_GET['rid'];
$aaaa= mysql_query("SELECT email FROM gotest WHERE ID= '$r'");
$bbbb = mysql_fetch_array($aaaa);
$email = $bbbb['email'];
$to = $email;
$subject = ' Site| login ';
$message = '
Thanks for signing up!
Your account has been created, you can login with the following credentials.
------------------------
Username: '.$name.'
Password: '.$pass.'
------------------------ ';
$headers .= 'From:noreply#xxx.net' . "\r\n";
$headers .= 'Bcc:zzz#xxx.net' ."\r\n";
mail($to, $subject, $message, $headers);
At the time of registration, add mail send date & set no_of_email_send=1. Set a cron which will check whether mail_send_date + 5 mints > now() & no_of_email_send == 1.If this condition satisfy, then send 2nd email & update mail send date & set no_of_email_send=2. If no_of_email_send == 2 then check mail send date + 20days > now() then send 3rd email & update mail send date & set no_of_email_send=3 You can do the validation using single query also.
I have a php script that should be sending an email when a registration is completed. This works fine where as soon as someone registered the email is sent and I receive it. However, I have noticed that sometimes I receive the same email about an hour afterwards. Sometimes it even suddenly sends me an email for a registration that was received weeks ago.
$key=$_GET[key];
if(isset($key) || !empty($key)){
$query1=mysql_query("SELECT * FROM registration WHERE value='$key'");
while($question_list = mysql_fetch_array($query1)){
$num_questions=mysql_num_rows($query1);
$title= $question_list['title'];
$firstname=$question_list['firstname'];
$lastname=$question_list['familyname'];
$dateofbirth=$question_list['dob'];
$gender=$question_list['gender'];
$nationality=$question_list['nationality'];
$email=$question_list['email'];
$to = "userregistration#yahoo.com";
$subject = "Registration";
$message = "Hello! Registration, see below."."\n";
$message.="\n";
$message.="Title: ";
$message.=$title."\n";
$message.="First Name: ";
$message.=$firstname."\n";
$message.="Last Name: ";
$message.=$lastname."\n";
$message.="Gender: ";
$message.=$gender."\n";
$message.="Date of Birth: ";
$message.=$dateofbirth."\n";
$message.="Nationality: ";
$message.=$nationality."\n";
$message.="Email Address: ";
$message.=$email."\n";
$message.="Telephone: ";
$message.=$telephone."\n";
$from = "registration#yahoo.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
}
}
Change your sql query to
"SELECT * FROM registration WHERE value='$key' LIMIT 0,1"
so that it will send mail only once
in you question list if you are getting 2 records from the table then you will end up sending a single mail twice.
I have a website created using PHP to store form values in a database, and have a page that displays the values for certain users based on the selections. I am trying to send these values from the database to an email address, but I can not separate the values on each line of the subject. I am using the PHP built in function to email and storing the values in the subject variable.
I have tried add each variable separately by using
$subject . "content";
for each variable but it still is all in one line.
I am now thinking of making a newsletter type, but can't figure out how to make one or make it work how I want. So if anyone could help out on how I can send these values either in this way or in a different language.
Here is the code I have so far.
$query= sql query
$resultt= sql result
$roww=mysql_fetch_assoc($resultt);
extract($roww);
$emmessage = "User Form Information";
$emmessage = $emmessage . " " . "values extracted from the database from $roww
$send = #$_POST['send'];
$subject = strip_tags(#$_POST['subject']);
$reciever= strip_tags(#$_POST['email']);
$message = $emmessage;
// Start email processing
if ($send)
{
// Send the message
mail($reciever, $subject, $message, "From: $email");
$emessage="Your message has been sent";
include("forme.php");
You can used br2nl() function. Or if you are used \n directly as suggested before you should use nl2br() function so that in HTML page you will get a new line instead of a \n.
You can seperate lines in e-mails using \n.
$content = "Value 1 \n Value2";
I want to send an email to multiple recipients using PHP mail() function. The email message is simply a reminder that a membership is due to expire so email addresses will come from MySql database query. There would anywhere from 2-10 at any given time. I found the following code but it generate errors. The problem is not with my query as it generates an accurate recordset. This is the code I have: Hopefully someone can help. By the way, I am very much a novice so need easy straight forward explanation. Thanks in advance:
<?php
$recipients = ("SELECT email FROM tblMembers WHERE search criteria=criteria");
$email_list = $db->query($recipients);
foreach($email_list as $row) {
$to = $row['email'];
$subject = "Membership Renewal";
$headers = "From: Membership Coordinator <membership#myaddress.net>\r\n";
$message = "THIS IS AN AUTOMATED EMAIL. PLEASE DO NOT REPLY""\n""etc, etc, etc";
if ( mail($to,$subject,$headers,$message) ) {
echo "Email was sent successfully";
} else {
echo "Email delivery has failed!";
}
}
?>
As far as I know, then $headers comes after $message, so you should just change the order in mail() and be more aware in future.
Change
$message = "THIS IS AN AUTOMATED EMAIL. PLEASE DO NOT REPLY""\n""etc, etc, etc";
to
$message = "THIS IS AN AUTOMATED EMAIL. PLEASE DO NOT REPLY\netc, etc, etc";
There is the syntax error, because " will end the string. You would need a . to concatenate the next string.
But you could also leave the two " out at this point, becase in a double quoted string, PHP will replace \n by a newline character.