php phpmailer always go to hotmail junk folder anyone can solve - php

<?php
$to=$_POST['email'];
$pwd=$_POST['pwd'];
$activate_code = md5($_POST['pwd'] . $_POST['email'] . time());
$subject = "卓能脹戶啟動程序" ;
$body ="親愛的 [$username] : <br />" .
"歡迎加入卓能會員網站! <br />" .
"請利用以下網址啟動您的帳號,才能完成註冊程序," .
"<a href=http://www.domain.com/activate.php?code=$gencode>http://www.domain.com/activate.php?code=$gencode</a> " .
"勿直接回覆此信 。 <br />" .
"<br /> 開啟動成功後您會員帳號即可立即使用。";
include("PHPMailer/class.phpmailer.php");
$mail= new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.domain.com";
$mail->Port = 25;
$mail->CharSet = "utf-8";
$mail->Username = "minniekwok223#domain.com";
$mail->Password = "123456";
$mail->From = "minniekwok223#domain.com";
$mail->FromName = "minnie kwok";
$mail->Subject = $subject;
$mail->Body = $body;
$mail->IsHTML(true);
$mail->AddAddress($to);
?>
who always go to hotmail junk folder anyone can help ?

Related

send email on localhost with PHP

I want to send an email on localhost but don't really know how to do it.
I tried some different ways but it doesn't work.
I used PHPMailer https://github.com/PHPMailer/PHPMailer/tree/5.2-stable as the mailserver but I think thats maybe wrong implemented or so.
Don't know if it's important but I use MAMP.
This is what I currently have:
<?php
if (isset($_POST['submit'])) {
require("PHPMailer/PHPMailerAutoload.php");
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true;
$mail->Username = "mail account";
$mail->Password = "password for account";
$mail->Port = "465";
$mail->setFrom('receiver mail', 'TEST');
$mail->addReplyTo('receiver mail', 'TEST');
$mail->addAddress('recipient mail');
$mail->Port = "465";
$mail->isHTML(true);
$mail->Subject = "test";
// get text from input fields
$email = $_POST['email'];
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$number = $_POST['number'];
$textarea = $_POST['textarea'];
$bodyContent =
"<p>Name: " . $name . "</p>
<p>E-Mail: " . $email . "</p>
<p>Telefonnummer: " . $number . "</p>
<p>Adresse: " . $address . $city . "</p>
<p>Anliegen: " . $textarea . "</p>";
$mail->Body = $bodyContent;
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
}
?>
Comment out the following two lines :
// ini_set("SMTP","ssl://smtp.gmail.com");
// ini_set("smtp_port","465");
And add the following under the line with $mail = new PHPMailer();
$mail->isSMTP();
And it will work, I have tried it on my laptop on XAMPP.
Okay, i finally found the solution. I updated my code to this
<?php
if (isset($_POST['sendButton'])) {
require("PHPMailer/PHPMailerAutoload.php");
require 'PHPMailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = "secret";
$mail->Password = "secret";
$subject = utf8_decode('test');
$mail->setFrom('secret', $subject);
$mail->addReplyTo('secret', $subject);
$mail->addAddress('secret');
$mail->Subject = utf8_decode('test');
$mail->Port = "587";
$mail->isHTML(true);
$email = $_POST['email'];
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$number = $_POST['number'];
$sendText = $_POST['sendText'];
$bodyContent =
"<p>Name: " . $name . "</p>
<p>E-Mail: " . $email . "</p>
<p>Telefonnummer: " . $number . "</p>
<p>Adresse: " . $address . ' ' . $city . "</p>
<p>Anliegen: " . $sendText . "</p>";
$mail->Body = $bodyContent;
}
?>
Besides I had to go to myaccount.google.com -> "Sign-in & security" -> "Apps with account access", and turn "Allow less secure apps" to "ON"
Now everything is fine.
Thank you for your help guys

I used phpmailer() concept to receive mail from users from my bigrock server using php script, but It's not working

This is my code:
<?php
require_once "PHPMailer/PHPMailerAutoload.php";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com"; //gethostbyname('smtp.gmail.com');
$mail->SMTPAuth = true;
$mail->SMTPDebug = 3;
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->Username = "ku***wa***ar***#gmail.com";
$mail->Password = "t***r9***5******7";
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress($mail->Username);
$mail->Subject = 'Contact form query / feedback';
$mail->Body = "
<div><span>Name : </span><span>{$name}</span></div>
<div><span>Email : </span><span>{$email}</span></div>
<div><p>{$message}</p></div>
";
$mail->isHTML(true);
if ($mail->send()){
echo "Your feedback/query is sent!";
}else{
echo "Error! Unable to forward your request.<br> Pleas try again later!";
}
Note: I have used " GMail " as my SMTP server and SMTPSecure is " ssl " and port is "465" and username & passwords are my GMail username & password
The Error Message is:
Screen Shot : https://s16.postimg.org/4hgsh9d51/smtp.png
Here is your code modified
<?php
include "PHPMailer_5.2.4/class.phpmailer.php";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com"; //gethostbyname('smtp.gmail.com');
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->isHTML(true);
$mail->Username = "hari.andoidsaiss#gmail.com";
$mail->Password = "supreme#12#";
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress($mail->Username);
$mail->Subject = 'Contact form query / feedback';
$mail->Body = "
<div><span>Name : </span><span>{$name}</span></div>
<div><span>Email : </span><span>{$email}</span></div>
<div><span>Message : </span><p>{$message}</p></div>
";
if ($mail->send()){
echo "Your feedback/query is sent!";
}else{
echo "Error! Unable to forward your request.<br> Pleas try again later!";
}

PHP SMTP Custom contact form

I have this form, that send fine locally, but when i upload it to hostgator i get the following error message
Mailer Error: Could not instantiate mail function.
my php code is
<?php
if(isset($_POST['submit'])){
require 'PHPMailer/PHPMailerAutoload.php';
// Send mail
$mail = new PHPMailer();
// Data received from POST request
$name = stripcslashes($_POST['tbName']);
$emailAddr = stripcslashes($_POST['tbEmail']);
$company = stripcslashes($_POST['tbCompany']);
$comment = stripcslashes($_POST['taMessage']);
$subject = stripcslashes($_POST['tbSubject']);
// SMTP Configuration
$mail->SMTPAuth = true;
$mail->Host = "gator3209.hostgator.com"; // SMTP server
$mail->Username = "****#*****.com";
$mail->Password = "***********";
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->AddAddress('****#*****.com');
$mail->From = "****#*****.com";
$mail->FromName = "Website Contact Form - " . $name;
$mail->Subject = $subject;
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML("Name:" . $name . "<br /><br />Email:" . $emailAddr. "<br /><br />Company:" . $company. "<br /><br />Subject:" . $subject. "<br /><br />" . $comment);
$message = NULL;
if(!$mail->Send()) {
$message = "Mailer Error: " . $mail->ErrorInfo;
} else {
$message = "Message sent!";
}
}
?>
I have spoken to my host and they said its not within there support to deal with these things, but said my port and host are correct.
So now I'm rather confused. is there anything obvious I'm missing?
Just to let you know if anyone finds this, my problem was i was missing $mail->IsSMTP(); from my config.
the SMTP config section should be as follows
<?php
if(isset($_POST['submit'])){
require 'PHPMailer/PHPMailerAutoload.php';
// Send mail
$mail = new PHPMailer();
// Data received from POST request
$name = stripcslashes($_POST['tbName']);
$emailAddr = stripcslashes($_POST['tbEmail']);
$company = stripcslashes($_POST['tbCompany']);
$comment = stripcslashes($_POST['taMessage']);
$subject = stripcslashes($_POST['tbSubject']);
// SMTP Configuration
$mail->SMTPAuth = true;
$mail->IsSMTP();
$mail->Host = "gator3209.hostgator.com"; // SMTP server
$mail->Username = "****#*****.com";
$mail->Password = "***********";
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->AddAddress('****#*****.com');
$mail->From = "****#*****.com";
$mail->FromName = "Website Contact Form - " . $name;
$mail->Subject = $subject;
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML("Name:" . $name . "<br /><br />Email:" . $emailAddr. "<br /><br />Company:" . $company. "<br /><br />Subject:" . $subject. "<br /><br />" . $comment);
$message = NULL;
if(!$mail->Send()) {
$message = "Mailer Error: " . $mail->ErrorInfo;
} else {
$message = "Message sent!";
}
}
?>

PHPMailer with attachment

So, i'm having problem with this code.
It's a form where it get the data and this is the phpmailer fragment, where i get the error Could not acess file
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message= $_REQUEST['message'];
$message= "--$boundary" . PHP_EOL;
$message= "Content-Type: text/html; charset='utf-8'" . PHP_EOL;
$message= "--$boundary" . PHP_EOL;
$tapete=$_REQUEST['tapete'];
$medidas=$_REQUEST['medidas'];
$cliente=$_REQUEST['cliente'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "mucapapipa.br#gmail.com";
$mail->Password = "----";
$mail->Subject = 'Formulário FacilityCom';
$mail->setFrom = ('mucapapipa.br#gmail.com');
$mail->Body = 'Tipo e marca: $tapete \nMedidas: $medidas \nCliente: $cliente\n $from';
$mail->IsHTML(true);
$mail->AddAttachment($file['tmp_name'], $file['name']);
$mail->Send();`
There's a lot wrong here.
Don't mess with boundaries - PHPMailer does all that for you.
$mail->setFrom = ('mucapapipa.br#gmail.com') should be $mail->setFrom('mucapapipa.br#gmail.com').
It would help if you based your code on the file upload example provided with PHPMailer as that shows how to handle file uploads correctly.

How to send multiple emails in PHP and MySQL via phpmailer

I have a problem. When i click send button, just zxc#hotmail.com receives the message.
How to change it? I'm use Gmail SMTP send out.
There are 2 records in the database:
Here is my code:
include "phpmailer/class.phpmailer.php";
$host = "localhost";
$user = "root";
$pass = "root";
$db = "mailTest";
mysql_connect($host, $user, $pass);
mysql_select_db($db);
$query = "SELECT email FROM list";
$recordset = mysql_query($query);
$row_recordset = mysql_fetch_assoc($recordset);
$tota_row_recordset = mysql_num_rows($recordset);
$msg = strip_tags($_POST['msg']);
$mail= new PHPMailer(); //建立新物件
while($row = mysql_fetch_array($recordset))
{
$to = $row['email'];
$mail->AddAddress($to, "Test Message");
}
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->CharSet = "big5";
$mail->Subject = "Test Message";
$mail->Username = "xxxxxx";
$mail->Password = "xxxxxx";
$mail->Body = "$msg";
$mail->IsHTML(true);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
header('Location: index.php');
}
With this loop you overwrite the recipient with each iteration, so only the last one stays to receive the email:
while($row = mysql_fetch_array($recordset))
{
$to = $row['email'];
}
$mail = new PHPMailer();
Change your code to
$mail = new PHPMailer(); // create object FIRST
while($row = mysql_fetch_array($recordset))
{
$to = $row['email'];
$mail->AddAddress($to, "Test Message"); // add each DB entry to list of recipients
}
try this below:
while($row = mysql_fetch_array($recordset))
{
$to = $row['email'];
$mail= new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->CharSet = "big5";
$mail->Subject = "Test Message";
$mail->Username = "xxxxxx";
$mail->Password = "xxxxxx";
$mail->Body = "$msg";
$mail->IsHTML(true);
$mail->AddAddress($to, "Test Message");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
if(isset($_POST['sbmit']))
{
for($i=0;$i<count($_POST['email_address']);$i++)
{
$to = $_POST['email_address'][$i];
echo $to."<br />";
$subject = 'Thank you for Subscribing';
$message = $_POST['news'];
$headers = 'From: dhakalneil#gmail.com' . "\r\n" .
'Reply-To: xyz#hotmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
echo $_POST['email_address'][$i]."<br />";
ini_set("SMTP","smtp.ntc.net.np" );
ini_set('sendmail_from', 'dhakalneil#gmail.com');
if( mail($to,$subject,$message,$headers))
{
echo "Mail has been sent to admin<br />";
}
else
{
echo "Mail could not been sent";
}
}
}
?>

Categories