user registration sends 2 emails - php

I am using a custom form, with a Joomla 1.6 Platform. The User email goes through fine, but the email notifing us of the sign up does not come through. Is it possible to send 2 emails back to back like this or is there an error in my code?
///----------------User Email After Registered----------------------------///
// Send notification email //
$to = $email;
$subject = "$hs2 Alumni Football Team";
$message = "
<html>
<head></head>
<body>
<h1>Alumni Football USA</h1>
<p> Hi $firstname,</p>
<p>You are now able to sign up for $hs2 games! Login to Reserve your spot!</p>
<p>Username: $username</p>
<p>Password: $showpass</p>
<p>$hs2 Alumni Football Team Page---$remail2 </p>
<p>This is an automatic Email, please do not respond/reply</p>
</body>
</html>
";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: Alumni Football USA<NOREPLY#alumnifootballusa.com>' . "\r\n";
// Send notification //
mail($to,$subject, $message, $headers);
///---------------Email site owner-----------------------------------------///
$phone1 = $cell;
$cell1 = formatPhone1($phone1);
$phone2 = $home;
$home1 = formatPhone2($phone2);
$query = "SELECT t_name FROM " . $table_prefix . "bl_teams WHERE id = ".$team_id;
$db->setQuery($query);
$hs2 = $db->loadResult();
$query = "SELECT ((date_format(now(),'%Y') - date_format(birthday,'%Y')) - (date_format(now(),'00-%m-%d') < date_format(birthday,'00-%m-%d')))
FROM " . $table_prefix . "users WHERE'".$email."' = username";
$db->setQuery($query);
$age45 = $db->loadResult();
$query = "SELECT t_city FROM " . $table_prefix . "bl_teams WHERE ".$team_id."= id ";
$db->setQuery($query);
$city5 = $db->loadResult();
$query = "SELECT s.s_descr FROM " . $table_prefix . "bl_seasons as s WHERE ".$s_id."= s.s_id ";
$db->setQuery($query);
$state = $db->loadResult();
$query = "SELECT u.email FROM " . $table_prefix . "users as u, " . $table_prefix . "bl_teamcord as tc WHERE tc.s_id = ".$s_id." AND FIND_IN_SET('$team_id',tc.teams) AND tc.u_id = u.id AND
tc.reg_emails = 1";
$db->setQuery($query);
$remail1 = $db->loadResultArray();
if ($remail1){
$remail = implode(",",$remail1);
}else{
$remail = "";}
// Send notification email //
$to = $remail;
$subject = "***Reserved***$hs2,$state --$firstname $lastname";
$message = "
<html>
<head><title>Alumni Football USA</title></head>
<body>
<h1>$firstname $lastname</h1>
</body>
</html>
";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: Alumni Football USA <webmaster#alumnifootballusa.com>' . "\r\n";
// Send notification //
mail($to,$subject, $message, $headers);
///--------------------------------------------------------------///

The problem might be you $to variable might not have email value:
if ($remail1){
$remail = implode(",",$remail1);
}
else{
$remail = ""; //you might have this
}
$to = $remail; //so if $remail is blank so will be the $to as well
So ensure your $to variable holds email,
if(!empty($to)) {
//send email
mail($to,$subject, $message, $headers);
}

Related

looping through emails created by database recordset

I wish to send an email to one address and cc to other addresses drawn from a table.
// get all cc email id's for this users site
$results3h = mysql_query("SELECT user_id FROM company_ccemails WHERE site_id = '$site_id' ");
echo mysql_error();
while($row = mysql_fetch_array($results3h))
{
$cc_id = $row['user_id'] ;
//get email addresses for each id
$results3i = mysql_query("SELECT username FROM user WHERE id = '$cc_id' ");
echo mysql_error();
while($row = mysql_fetch_array($results3i))
{
$ccemails = $row['username'] . "," ;
}
mysql_free_result($results3i);
}
mysql_free_result($results3h);
//send emails to
$to = "support#mydomain.com ; ";
$subject = "$email_subject";
$message = "$email_message";
$headers = "CC: " .$ccemails. "\r\n";
$headers .= "From: " . strip_tags($myusername) . "\r\n";
$headers .= "Reply-To: ". strip_tags($myusername) . "\r\n";
$headers .= "BCC: " .$myusername. "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers);
when sending this email only the 'to' and 1 'cc' is sent although there are 3 'cc' email address. if I move the send code under $ccemails = $row... then an email is sent to each 'cc' separately along with support#mydomain.com. this results in support# getting lots of emails.
how do I change the code to get the cc emails in one string and send as one email so support only receives one copy?
I'm relatively new to PHP coding (usually ASP) and am sure this is straight forward but is confusing me at the moment
thanks for any help
With $ccemails = $row['username'] . "," ; you are assigning the value of $row['username'] to your $ccemails variable. This means you override it everytime in the loop.
You have to concat the string with .=
Try this below:
$ccemails = ""; // define this here, because otherwise you will get a notice
while ( $row = mysql_fetch_array( $results3h ) ) {
/**
* Your code
*/
while ( $row = mysql_fetch_array( $results3i ) ) {
$ccemails .= $row['username'] . ",";
}
/**
* Your code
*/
}

PHP send mail with question marks although using utf-8

Using the following php file to send mail.
But the text that is not English inside the mail body get as ???? and the $subject of the mail get as "‚º ëÃ"
what do I need to check/add/change in order to fix it?
<?php include('config.php');
header('Content-Type: text/html; charset=utf-8');
class messenger
{
public $name;
public $number;
public $email;
public $address;
public $category;
public $tool;
/*----------user registration start--------------*/
function signup()
{
$name = $_REQUEST['name'];
$number = $_REQUEST['number'];
$email = $_REQUEST['email'];
$address = $_REQUEST['address'];
$category = $_REQUEST['category'];
$tool = $_REQUEST['tool'];
$datetime = date("Y-m-d H:i:s");
//Generate the email message:
$to = 'someEmailAddress#gmail.com';
$subject = "הזמנת חדשה";
$msg = "In time: " . $datetime . "\n New Power Tool Rental: \n\n Name: " . $name . "\r\n Email: " . $email . "\n Mobile Number: " . $number . "\n Address: " . $address . "\n Category: " . $category . "\n Tool: " . $tool . "\n\n Regards\n " . $name . " \n " . $email;
$headers = "From: $email" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8";
$headers .= "X-Mailer: PHP/" . phpversion();
//Send the email
mail($to, $subject, $msg, $headers);
//Enter data to the SQL table
$sql = "INSERT INTO user (name, number, email, address, category, tool, dateTime)
VALUES ('$name', '$number', '$email', '$address', '$category', '$tool','$datetime')";
//Check if entered to SQL and if Yes send back in json message
$result = mysql_query($sql);
if (!$result) {
$message["result"] = "Problemmm";
} else {
$mysql_insert_id = mysql_insert_id(); //get the new ID number from sql table
$message["id"] = $mysql_insert_id; //add the new ID data to the response message
$message["name"] = $_REQUEST['name'];
$message["number"] = $_REQUEST['number'];
$message["email"] = $_REQUEST['email'];
$message["address"] = $_REQUEST['address'];
$message["result"] = "successfully";
}
//Send back the json message
echo json_encode($message);
die;
}
/*----------user registration end--------------*/
}
?>
just tried to change the subject to:
$subject = "הזמנת כלי להשכרה";
$encSubject = '=?UTF-8?B?'.base64_encode($subject).'?=';
now I get the subject of the mail as:
���ú ��é ��
Setting the headers is not enough.
Both subject (must be RFC 2047) and
message (must be UTF-8 in your case) have also be in their respecive correct encoding, the php::mail doc + user-notes covers most of what you miss.

Issues getting SQL statement to select the items I want it to

I'm trying to send an email to users with the group level of 4 or 5. I have the group levels distinguished in my 'users' table. I'm trying to get the email and 'firstname' of the users with the 'group' level of 4 or 5. Then to use that email and first name to create variables with it and use it for my email.
Am I structuring my SQL statement incorrectly? I am not getting any errors.
The area where I am struggling with are these lines.
if($sql_email = "SELECT 'email' FROM 'users' WHERE 'group' = 4 AND 5") {
$email = $con->query($sql_email);
} else {
echo "Query not working right";
}
$sql_name = "SELECT 'firstname' FROM 'users' WHERE 'group' = 4 AND 5";
$admin_name = $con->query($sql_name);
More code to show how I am using it
ini_set('display_errors', 1);
error_reporting(E_ALL);
//User Request Email that goes to the commissioner and creator
if(isset($_POST['submit'])) {
$con = mysqli_connect("localhost","root","","db");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if($sql_email = "SELECT 'email' FROM 'users' WHERE 'group' = 4 AND 5") {
$email = $con->query($sql_email);
} else {
echo "Query not working right";
}
$sql_name = "SELECT 'firstname' FROM 'users' WHERE 'group' = 4 AND 5";
$admin_name = $con->query($sql_name);
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$to = $email;
$subject = 'There is a new user request to join the SFL';
$message = '
<html>
<head>
<title>New SFL User Request</title>
</head>
<body>
<p>Hi '.$admin_name.',</p><br>
<p>Thank you for wanting to join the!</p>
<p>Thank you,</p>
<p>Administration</p>
</body>
</html>
';
$from = "user-requests#example.com";
$Bcc = "user-requests-confirm#example.com";
// 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";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
}
UPDATE
$sql_email = "SELECT `email` FROM `users` WHERE `group` = 4 OR `group` = 5";
$email = $con->query($sql_email);
if( ! $con->query($sql_email) )
echo "Query not working right";
$sql_name = "SELECT `firstname` FROM `users` WHERE `group` = 4 OR `group` = 5";
$admin_name = $con->query($sql_name);
I get this error..
Catchable fatal error: Object of class mysqli_result could not be converted to string in /home4/db/public_html/example.com/register.php on line 219
Line 219 is this...
<p>Hi '.$admin_name.',</p><br>
After you execute a select query, you need to fetch records. I assume you need to send email to all users found.
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$sql_email = "SELECT `email`, `firstname` FROM `users` WHERE `group` IN (4,5)";
$users = $con->query($sql_email);
if (($users) && ($users->num_rows > 0)){// Got any record?
// output data of each row
while($user = $users->fetch_assoc()){
$to = $user['email'];
$subject = 'There is a new user request to join the SFL';
$message = '
<html>
<head>
<title>New SFL User Request</title>
</head>
<body>
<p>Hi '.$user['firstname'].',</p><br>
<p>Thank you for wanting to join the!</p>
<p>Thank you,</p>
<p>Administration</p>
</body>
</html>
';
$from = "user-requests#example.com";
$Bcc = "user-requests-confirm#example.com";
// 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";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
}
}
else{
echo "No User Found!";
}
You can learn more from here: Select Data With MySQLi
SELECT anything FROM `users` WHERE `group` = 4 OR `group` = 5
Besides,
if($sql_email = "SELECT 'email' FROM 'users' WHERE 'group' = 4 AND 5")
is useless as the result will always be true.
You can say
if( ! $con->query($sql_email) )
echo "Query not working right";

Mailer not reaching Microsoft email users

Clients with Microsoft email accounts such as Live or Office 365 are not receiving the Alert email sent out with the code below. Texting feature and Yahoo and Gmail work. A link is run on the computer prompting a location to be shared and an email & text to be sent out.
The email used to send the email out is through Office 365. Can anyone take a look at this. Am I missing something?
I have tried using PHP Mailer, but it does the exact same thing. Any Help!
<html>
<head>
<title>Redirecting</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<?php
setcookie("tracker", 1, time()+1800);
$queryString = $_SERVER['QUERY_STRING'];
//$stripped = substr($queryString,strpos($queryString,"i")+1)
$count=-6;
$id=substr($queryString,$count,6);
//start email alert
//connect to database
//db connection
$db = new mysqli('localhost', 'smart', 'smart', 'smarter');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
// associate carrier with correct ending
$query = "SELECT * FROM `smarter` where id = '$id'";
$result = $db->query($query);
$row = $result->fetch_assoc();
$email = $row['email'];
$emailSMS = $row['emailSMS'];
$ownername = $row['ownername'];
$txt_alert = $row['txt_alert'];
$number = $row['phoneone'] . $row['phonetwo'] . $row['phonethree'] . $row['carrier']; // var works
$emailSMS = 1;
if ($txt_alert == "yes")
{
$email_to = $email . " , " . $number;
}
else if ($txt_alert == "no")
{
$email_to = $email;
}
//check to see if tag has been registered
if ($_COOKIE["tracker"] == 1) {
$number = $row['phoneone'] . $row['phonetwo'] . $row['phonethree'] . $row['carrier']; // var works
//check to see if tag has been registered
$host = "smtp.office365.com";
$port = "587";
$username = "support#xxxx.com";
$password = "xxxxxx";
$datetime = date("D M j G:i:s T Y");
$subject = "Alert";
$mailheader.= "From: " . "Smart Recovery Tag Team <support#xxxx.com>\n";
$mailheader.= "X-Sender: " . "support#xxxx.com\n";
$mailheader.= "Return-Path: " . "support#xxxx.com\n";
$mailheader .= "Bcc: support#xxxx.com";
$body .= "Dear " . $ownername . ", \n\n";
$body .= "Your tag has just been scanned.\n\n";
$body .= "Click here to Login to your profile\n";
$body .= "http://www.tag.com\n";
$body .= "***************\n";
$body .= " Login to your profile to see a map of the last GPS location. \n\n";
$body .= "Scanned on " . $datetime . ". \n\n";
$body .= "Regards,";
$body .= " \n\n";
$body .= "Tag Team";
$body .= " \n\n";
$body .= "Keeping found";
if ($txt_alert == "yes")
{
mail($email, $subject, $body, $mailheader, ) or die ("Mail could not be sent.");
mail($number, $subject, $body, $mailheader, ) or die ("Mail could not be sent.");
}
else if ($txt_alert == "no")
{
mail($email, $subject, $body, $mailheader ) or die ("Mail could not be sent.");
}
//send email
$_COOKIE["tracker"] = 0;
}
header("Location: http://www.smartrecoverytag.com/profile.php?id=$id");
mysql_close($db);
?>
</body>
</html>

how to send email automatically when a value is updated in mysql database

i design an application and build with phonegap all is working but when a value in my mysql database that is attached the app is updated i want an email to be sent automatically to the user. When the counter completes counting the value of "status" in runnindAds table is updated and i want to an email to be sent each time that value is updated, below is the script i wrote for the email to be sent but i don't know how to automate it, please help with what i can should or i can
<?
include('../db_connect.php');
require_once "PHPMailer-master/class.phpmailer.php";
$id=$_GET["rid"];
$status = 3;
mysql_query("update runningAds set status = 3 where id = '$id'");
// get username
$qaz = mysql_query("select * from runningAds where id = $id") or die (mysql_error());
$wsx = mysql_fetch_array($qaz);
$username = $wsx["users"];
$stopTime = $wsx['stopTime'];
sendConfirmationEmail($username, $stopTime);
header("location: ../view_running_ads.php");
function sendConfirmationEmail($username, $stopTime)
{
$result2 = mysql_query("select * from dapUsers where userName='$username'");
$row = mysql_fetch_array($result2);
$to = $row['email'];
//$from = "admin#addirectng.com";
$subject = 'Advert Runtime Alert';
$message = "Dear $username,<br \>
Your display picture advert runtime has ended at $stopTime. <br \>
Advert Direct Team";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <admin#addirectng.com>' . "\r\n";
mail($to,$subject,$message,$headers);
}
?>
Try this:
<?php
include('../db_connect.php');
require_once "PHPMailer-master/class.phpmailer.php";
$id=$_GET["rid"];
$status = 3;
// get username
$qaz = mysql_query("select * from runningAds where id = $id") or die (mysql_error());
$wsx = mysql_fetch_array($qaz);
$username = $wsx["users"];
$stopTime = $wsx['stopTime'];
if (mysql_query("update runningAds set status = 3 where id = '$id'"))
{
sendConfirmationEmail($username, $stopTime);
}
header("location: ../view_running_ads.php");
function sendConfirmationEmail($username, $stopTime)
{
$result2 = mysql_query("select * from dapUsers where userName='$username'");
$row = mysql_fetch_array($result2);
$to = $row['email'];
//$from = "admin#addirectng.com";
$subject = 'Advert Runtime Alert';
$message = "Dear $username,<br \>
Your display picture advert runtime has ended at $stopTime. <br \>
Advert Direct Team";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <admin#addirectng.com>' . "\r\n";
mail($to,$subject,$message,$headers);
}
?>
Tell me if it works or not.

Categories