Mailer not reaching Microsoft email users - php

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>

Related

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.

Reservation system with confirmation mail in PHP

Like the titles shows I'm making a reservation system in HTML/PHP. First a (HTML) form needs to be filled in and those values are passed to the reservation-send.php file. That .php file generates an email message with couple of values from the form and a confirmation link (incl. hash code) that will be send to the person who will confirm. When the link is pressed it will trigger another .php file, bevestiging.php. That file checks the hash code and email and if correct send another email that the confirmation has been made.
But always getting "error!". I think the output for my url confirmation link is the issue.. (see image)
PHP - reservation-send.php
<?php
require_once 'inc/securimage/securimage.php';
/////////////////////////////////////
// Change this email address ////////
$email = "test#test.be"; //make this test#test.be on purpose ;)
/////////////////////////////////////
$required = array('day', 'month', 'year', 'hour', 'minutes', 'ampm', 'name', 'email', 'captcha', 'phone', 'amount');
$response = array('status' => 'failed', 'errors'=>array());
if(isset($_POST['reservation'])) {
foreach($_POST['reservation'] as $field => $value) {
//check required field if empty
if($value == '' && in_array($field, $required)) {
$response['errors'][$field] = $field;
}
}
//validate email
if(!isset($response['errors']['email'])) {
if(!filter_var($_POST['reservation']['email'], FILTER_VALIDATE_EMAIL)) {
$response['errors']['email'] = 'email';
}
}
//validate captcha
if(!isset($response['errors']['captcha'])) {
$securimage = new Securimage();
if ($securimage->check($_POST['reservation']['captcha']) == false) {
$response['errors']['captcha'] = 'captcha';
}
}
}
if(empty($response['errors'])) {
$response['status'] = 'success';
$data = $_POST['reservation'];
//Generate email link
//save mail of who made the reservation - get from form
$email_reservering =$data['email'];
//generate hash code
$hash = md5($email_reservering);
//generate link with hash code
$link = "http://lanes.be/baronie/bevestiging.php?email=”.urlencode($email_reservering).”&hash=$hash";
$headers = "";
$message .= "Dag Lode en Eva, via de website kregen jullie een nieuwe reservatie, gelieve de persoon zo snel mogelijk een bevestigingsmail te sturen!";
$message .= "\n\n";
$message = $data['message'];
$message .= "\n\n";
$message .= " Telefoon: " . $data['phone'];
$message .= "\n\n";
$message .= " Lunch/Diner: " . $data['booking-type'];
$message .= "\n\n";
$message .= " Aantal personen: " . $data['amount'];
$message .= "\n\n";
$message .= " Email: " . $data['email'];
$message .= "\n\n";
$message .= " Datum: " . $data['day'];
$message .= "\n\n";
$message .= " Maand: " . $data['month'];
$message .= " " . $data['year'];
$message .= "\n\n";
$message .= " Tijdstip: " . $data['hour'] . " " . $data['minutes'] . " " . $data['ampm'];
$message .= "\n\n\n\n";
$message .= "<a href='".$link."'>Bevestig</a>";
$subject = 'Nieuwe reservatie via de website';
$headers = 'From: '. $data['email']. "\r\n" .'Reply-To: '. $data['email']. "\r\n" .'X-Mailer: PHP/' . phpversion();
if (mail($email, $subject, $message, $headers)) {
} else {
$response['status'] = 'failed';
}
}
echo json_encode($response);
PHP - bevestiging.php
<?php
//retrieve email and hash code from link
$email_reservering = urldecode($_GET['email_reservering']);
$hash = $_GET['hash'];
//check if hash code matches
if (md5($email_reservering) == $hash)
{
//succes
$headers = "";
$message .= "reservering bevestigd!";
$message .= "\n\n";
$subject = 'Bevestiging reservering';
if (mail($email, $subject, $message, $headers)) {
} else {
$response['status'] = 'failed';
}
}
else
{
//error
echo "error!";
}
?>
Output
Reason of error (I think)
$link = "http://lanes.be/baronie/bevestiging.php?email=”.urlencode($email_reservering).”&hash=$hash";
or
$message .= "<a href='".$link."'>Bevestig</a>";
$link is build the wrong way. Look at the quotes i replaced.
Change it to this:
$link = "http://lanes.be/baronie/bevestiging.php?email=".urlencode($email_reservering)."&hash=".$hash;
Also, you dont need to urldecode $_GET variables

Contact form php script sending spam to Gmail

I created a php script (for a contact form) to send emails to my Gmail account.
If I use the sender email in the header ($headers = "From: " . $email;), Gmail reports the received message as spam.
If I don't use the email in the header (e.g. the sender name $headers = "From: " . $name;) the message is not reported as spam.
Do you have any suggestion to let me use the email in the header?
Thanks!
<?php
/* Check if the url field is empty (antispam) */
if ($_POST['leaveblank'] != '' or $_POST['dontchange'] != 'http://') {
$name = $_POST['name'];
$faillink = "xxx.php";
header("Location: $faillink");
} else {
$name = $_POST['name'];
$email = $_POST['email'];
$subject_prefix = "[ContactForm]: ";
$subject = $subject_prefix . $_POST['subject'];
$message = $_POST['message'];
$to = "myemail#gmail.com";
$body = "From: " . $name . "\n";
$body .= "Email: " . $email . "\n";
$body .= "Message: " . $message . "\n";
$headers = "From: " . $email;
$oklink = "yyy.php";
$faillink = "xxx.php";
if ( preg_match( "/[\r\n]/", $name ) || preg_match( "/[\r\n]/", $email ) ) {
header("Location: $faillink");
}
$retmail = mail($to, $subject, $body, $headers);
if ($retmail) {
header("Location: $oklink");
} else {
header("Location: $faillink");
}
}
?>
I solved the issue as Iain suggested so I replaced the mail headers as follows:
$headers = "From: " . "noreplay#mydomain.com" . "\r\n";
$headres .= "Reply-To: " . $email . "\r\n";

PHP Sending Duplicate Emails

After some more troubleshooting I believe I found the problem. We use QR Tags for our product and when a QR code is scanned it takes the user to the URL that runs this script. If I manually type in the URL or if I use our custom built QR scanner app then the user will receive one email. However if I user any other QR scanning app then it will send multiple emails. How can I make it so that this script will run only once each time the URL is loaded even if its from a third party app?
<?php
$queryString = $_SERVER['QUERY_STRING'];
$count=-6;
$id=substr($queryString,$count,6);
//db connection
$db = new mysqli('localhost', '*****', '*****', '*****');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "SELECT * FROM `****` where id = '$id'";
$result = $db->query($query);
$row = $result->fetch_assoc();
$email = $row['email'];
$ownername = $row['ownername'];
$petname = $row['petname'];
//check to see if tag has been registered
if ($email != "") {
//send email
$datetime = date("D M j G:i:s T Y");
$subject = "Alert";
$mailheader.= "From: " . "Tag Team <support#tag.com>\n";
$mailheader.= "X-Sender: " . "support#tag.com\n";
$mailheader.= "Return-Path: " . "support#tag.com\n";
$mailheader .= "Bcc: support#tag.com";
$body .= "Dear " . $ownername . ", \n\n";
$body .= "" . $petname . "'s Tag has just been scanned.\n\n";
$body .= "Click here to Login :\n";
$body .= "http://www.tag.com\n";
$body .= "********************\n\n";
$body .= "Regards,";
$body .= " \n\n";
$body .= "Tag Team";
$body .= " \n\n";
$body .= "Keeping Pets Safe and Found";
mail($email, $subject, $body, $mailheader ) or die ("Mail could not be sent.");
//end email alert
}
header("Location: http://www.smartphonepettag.com/id/profile.php?id=$id");
mysql_close($db);
?>
In the code snippet I cannot see any reason why your script should be executed more than once but relating to your post yesterday it seems as if something on your mail server is going terribly wrong.
But anyway if it's not an mail server fault the solution would be something like this:
// add this at the very first line
session_start();
// add this in the code
if($_SESSION['send'] != true){
mail($email, $subject, $body, $mailheader ) or die ("Mail could not be sent.");
$_SESSION['send'] = true;
}
This will make sure that the "mail()" function will never be executed twice for the same user.
You can learn more about Session Variables at the PHP manual.
You could create a flag in your database indicating if the email has been sent. Check the flag before sending the email, set it after you send the email.

user registration sends 2 emails

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);
}

Categories