I want to make a birthday reminder and from here I don't know what to do.
In my MySQL users DB U have birthdate with [month/day/year] And is not working,no error, i updated my bday with this day and still no activity.
This is what I have so far:
<?php
$conn = new PDO('mysql:host=localhost;dbname=tbl', 'user', 'pass');
$today = date("m.d.y");
$sqlb = "SELECT `birthdate`, `name`, `surename` FROM `mls_users` WHERE birthdate = '$today'";
$userz = $conn->query($sqlb);
foreach ($userz as $row) {
$name = $row['name'];
$surename = $row['surename'];
echo 'Todays is'.$name.' '.$surename.' birthday';
}
?>
I suppose you want to create an email notification.
$mail_content = '';
foreach ($userz as $row) {
$name = $row['name'];
$surename = $row['surename'];
$mail_content .= 'Todays is'.$name.' '.$surename.' birthday. <br>';
}
// send mail to you
// mail code
if($mail_content){
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $mail_content, $headers);
}
If you have the users email IDs saved in your Db you can send email to them
foreach ($userz as $row) {
$name = $row['name'];
$surename = $row['surename'];
//mail code
//email message
$mail_content = 'Happy birthday '.$name.' '.$surename.' !. <br>';
$to = $row['user_email']; //users email field
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $mail_content, $headers);
}
You can automate the script executing process using CRON Job
Related
<?php
$path = 'data.txt';
if (isset($_POST['email']) ) {
$fh = fopen($path,"a+");
$string = $_POST['email'].' - '.$_POST['field2'];
fwrite($fh,$string); // Write information to the file
fclose($fh); // Close the file
}
$to = $_POST['email'];
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Can someone tell me what is wrong with this code?
I want that the script to send email to $_POST['email'] that came from a previous html file.
So first,store that email,and after that sent an email to it.
Thank you
Edit: The script store the email with success but the email is not sent.
Thanks again
I've got stuck trying to echo multiple rows from a MySql database into the $message part of the email. The attached code only returns one result.
I want to send 1 email, in the email I want to output the 10 rows from the SQL query.
I actually receive the same email ten separate times rather than one email with ten rows.
$sql = "SELECT * FROM stoic_quotes Order By rand() Limit 0,10";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$to = 'email#email.com';
$subject = 'Daily Stoic Email';
$message = $row["Maxim"]. "</br>";
$headers = 'From: email#email.com' . "\r\n" .
'Reply-To: email#email.om' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
Move the mail call out of the loop
// don't select all (*) fields if you only need one
$sql = "SELECT Maxim FROM stoic_quotes Order By rand() Limit 0,10";
$result = $conn->query($sql);
$message = '';
while($row = $result->fetch_assoc()) {
$message .= $row["Maxim"]. "</br>";
}
// prepare email headers
$to = 'email#email.com';
$subject = 'Daily Stoic Email';
$headers = 'From: email#email.com' . "\r\n" .
'Reply-To: email#email.om' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// then send
mail($to, $subject, $message, $headers);
I haven't tested the code but give this a try:
$to = 'email#email.com';
$subject = 'Daily Stoic Email';
$sql = "SELECT * FROM stoic_quotes Order By rand() Limit 0,10";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$message = $row["Maxim"]. "</br>";
}
$headers = 'From: email#email.com' . "\r\n" .
'Reply-To: email#email.om' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
I have placed the to, subject, header and mail function out of the loop.
Cheers
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am trying to send an email using php but unable to do it, whereas I am getting data into MySQL database.
I have posted my whole code, please check and let me know where's the mistake.
$objConnect = mysql_connect("localhost","username","pwd");
$objDB = mysql_select_db("database");
$strName = $_POST["name"];
$strEmail = $_POST["email"];
$to = $strEmail;
$subject = 'the subject';
$message = 'hello';
$headers = 'From: mymail#gmail.com' . "\r\n" .
'Reply-To: mymail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$strSQL = "insert into data (name, email) VALUES ('".$strName."','".$strEmail."')";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr['StatusID'] = "0";
$arr['Message'] = "Cannot save data!";
}
else
{
mail($to, $subject, $message, $headers);
$arr['StatusID'] = "1";
$arr['Message'] = "Data saved successfully";
}
mysql_close($objConnect);
echo json_encode($arr);
This code is really working ...
<?php
$to = 'to_email#gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: mymail#gmail.com' . "\r\n" .
'Reply-To: mymail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$errLevel = error_reporting(E_ALL ^ E_NOTICE); // suppress NOTICEs
if(!mail($to, $subject, $message, $headers)){
error_reporting($errLevel);
}
?>
You have not added mail() function in your code then how will it send the mail and to send email from localhost it should be properly configured. Below code will work on the server.
$objConnect = mysql_connect("localhost","username","pwd");
$objDB = mysql_select_db("database");
$strName = $_POST["name"];
$strEmail = $_POST["email"];
$to = $strEmail;
$subject = 'the subject';
$message = 'hello';
$headers = 'From: mymail#gmail.com' . "\r\n" .
'Reply-To: mymail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(!mail($to, $subject, $message, $headers)){
echo 'Mail cant be send';
}
else
{
$strSQL = "insert into data (name, email) VALUES ('".$strName."','".$strEmail."')";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr['StatusID'] = "0";
$arr['Message'] = "Cannot save data!";
}
else
{
mail($to, $subject, $message, $headers);
$arr['StatusID'] = "1";
$arr['Message'] = "Data saved successfully";
}
echo json_encode($arr);
}
mysql_close($objConnect);
I have some affiliate script that I buy, however this script doesn't have function to
"Send password and login id to all my affiliate" weekly or maybe once per 2 week.
This is because in my experience he/she do not have many members not coming back because not only forgot password but also forgot username.
I want every month the members get email example
To: cubaan04#hotmail.com
From : admin#admin.com
Subject : Reminder : Your login name and password for website
Hi Firstname,
We worry if you forgot your login name and password. We love to see you back and active in our network. Here the detail...
your login name : Cubaan04
your password : Cubaan04
please login to website
Your truely
admin website
I found this script but dont know how to modified it
<?php
$db = mysql_connect("localhost", "plazacen_t", "plazacentrey");
mysql_select_db("plazacen_rak",$db);
$result = mysql_query("SELECT `email` FROM `affiliate_users`");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
sendMail($row[0]);
}
mysql_free_result($result);
function sendMail($to){
$subject = 'the subject';
$message = 'hello Shahrul';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
it not work
and how to put password and login in massage from the database?
Thanks you for read this, iam just noob for this
hope get help from you guys
updated
From our friend answer, i modified it. Yes it send email now but not work like i want, i put
<?php
$db = mysql_connect("localhost", "plazacen_rak", "rakan852");
mysql_select_db("plazacen_rak",$db);
$result = mysql_query("SELECT email,password,name FROM `affiliate_users`");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
sendMail($row[0],$row[1],$row[2]);
}
mysql_free_result($result);
function sendMail($to,$pwd,$id){
$subject = 'the subject';
$message = 'your login name:". $id ." password: ". $pwd ."';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
what I received is email like this;
From : webmaster#example.com
the subject
04/04/2015 9.59 PM
your login name:". $id ." password: ". $pwd ."
it is not change the $id to username in database, so do the $pwd
don't know whats wrong, any further help. TQ
The problem is with your sendMail function, You cannot take variables inside single quotes modify it as
function sendMail($to,$pwd,$id){
$subject = 'the subject';
$message = "your login name: {$id} password: {$pwd}";
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
another alternative could be
function sendMail($to,$pwd,$id){
$subject = 'the subject';
$message = 'your login name:' . $id .' password: '. $pwd;
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
Both will work like a charm.
First change your query to:
$result = mysql_query("SELECT email,password,userid FROM `affiliate_users`");
Then change your code like this:
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
sendMail($row[0],$row[1],$row[2]);
}
mysql_free_result($result);
function sendMail($to,$pwd,$id){
$subject = 'the subject';
**$message = "your login name:". $id ." password: ". $pwd ."";**
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
Note
I do not know what your field names are in the affiliate_users table so replace this "email,password,userid" with your actual field name.
If you want to execute this script every month then you can use cronjob.
complete beginner at PHP and was wanting a little direction for a website I am creating. I want the admin of the website to receive an email with all of the form information aswell as it being stored in the database. The database is storing the information fine, just need an email notification. How is this achieved. My PHP code is:
<?php
session_start();
include('connection.php');
$product = $_POST['product'];
$productcomments = $_POST['productcomments'];
$name = $_POST['name'];
$address = $_POST['address'];
$age = $_POST['age'];
$delivery = $_POST['delivery'];
mysql_query("INSERT INTO orderform(product, productcomments, name, address, age, delivery)VALUES('$product', '$productcomments', '$name','$address', '$age', '$delivery')");
header("location: google.com");
$to = 'j_bussey#live.co.uk';
$subject = 'Order';
$message = 'Product: ' . $product . '<br /> Product Comments: ' . $productcomments . '<br /> ';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
mysql_close($con);
?>
this is the very basic example of mail function. read more about mail() manual here.
$email = $_POST['email'];
$subject = "Email Subject";
$message = "Email Message Body";
mail($email, $subject, $message, "from: admin#yourdomain.com");
PHP has an awesome mail() function. I'm taking this from the documentation page here: http://us2.php.net/manual/en/function.mail.php
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
So since you're already grabbing the variables, you would just edit the $message variable in the code above to look something like this:
$message = 'Product: ' . $product . '<br /> Product Comments: ' . $productcomments . '<br /> ';
etc, etc. If you don't want to assume that they have html emails enabled, you would use \n instead of <br />
Edit:
You also need to change your header('Location: google.com'); to header('Location: http://www.google.com'); or wherever you want to redirect after the email has been sent off.