I've been trying to make a small E-mail function, so it's possible to send an E-mail to my Outlook from my website. But I'm running into some problems..
Do I have to change anything in my php.ini (xampp)? and username and password should be my outlook usn/pass right?
When I run this .php it says: echo "Mail Not Sent";
Can't really see what I'm doing wrong.
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 0;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.office365.com";
$mail ->Port = 587; // or 587
$mail ->IsHTML(true);
$mail ->Username = "mhoegstrup#company.com";
$mail ->Password = "XXXX";
$mail ->SetFrom("mhoegstrup#company.com");
$mail ->Subject = "Test";
$mail ->Body = "HEJJ";
$mail ->AddAddress("mhoegstrup#company.com");
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
The file PHPMailer is from: https://drive.google.com/file/d/0BzlVPBUP5IM8dmpDZ2tEZjdRaEU/view
Thanks for the help!
I checked documentation and settings of outlook service:
I realized you just need to set SMTPSecure to PHPMailer::ENCRYPTION_STARTTLS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
Related
Hello I am making a php based mailing application that will connect with a external smtp server and send emails. Now I have managed to match everything but the Message-ID's #domain-name and Sender domain name are not matching...
This is the result I am getting :
Wrong Message ID Header
and this is the result I should be getting (this email is sent from Mailwizz connected with the same SMTP server I am trying to connect with my application)
Expected Message ID Header
send.php file which I am using to connect with SMTP using PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/Exception.php';
require 'PHPMailer/PHPMailer.php';
require 'PHPMailer/SMTP.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp*****************';
$mail->SMTPAuth = true;
$mail->Username = 'notify#send.al***********';
$mail->Password = '**********';
$mail->SMTPSecure = 'tls';
$mail->Port = 80;
$mail->SetFrom('jon#al***********','John Adams');
$mail->Sender = 'notify#send.al*********';
$mail->addAddress('*********#gmail.com');
$mail->Subject = 'Hello This is a TEST FROM SMTP';
$mail->isHTML(false);
$mail->Body = 'Hello let me know when its received';
$mail->addCustomHeader('X-Sender', 'notify#send.al**********');
$mail->XMailer=null;
$mail->MessageID = md5('HELLO'.(idate("U")-1000000000).uniqid()).'-'.$type.'-'.$id.'#send.al*********';
if(!$mail->send()){
echo 'Error is '.$mail->ErrorInfo;
}
else{
echo 'Message has been sent!';
}
?>
In my experience, you do not need to use addCustomHeader if you want to set the MessageID.
Assuming that you want to set the Message ID to be [random]#send.alok, then please use the following:
$mail->MessageID = "<" . md5('HELLO'.(idate("U")-1000000000).uniqid()).'#send.alok>';
Hence, please the following will be ok:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require './Exception.php';
require './PHPMailer.php';
require './SMTP.php';
$user='smtp_xxxxxx_user';
$pass='smtp_password';
$mail = new PHPMailer(true);
try {
$mail->CharSet ="UTF-8";
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.xxxxx.com';
$mail->Username = $user;
$mail->Password = $pass;
$mail->MessageID = "<" . md5('HELLO'.(idate("U")-1000000000).uniqid()).'#send.alok>';
$mail->setFrom('jon#alxxxx.com', 'Jon Al');
$mail->addAddress('jon#gmail.com');
$subject="test";
$message="test123";
$mail->Port = 25;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
// echo 'Success';
} catch (Exception $e) {
//echo 'Failed';
}
?>
You may refer to the screen dump below for the result
This is my qr_code.php file:
require_once 'phpqrcode/qrlib.php';
function create_QrCode($name){
$path ='images/';
$file=$path.uniqid().".png";
$text=$name;
QRcode::png($text, $file);
}
?>
This is my mail.php file:
require('qr_code.php');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'C:\xampp\htdocs\contact_form\vendor\autoload.php';
#Initialize PHPMailer
function Send_email($mailFrom,$User_name,$phone,$city,$facebook,$qrCode){
$mail= new PHPMailer();
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail ->isSMTP();
$mail ->SMTPAuth =true;
$mail ->SMTPDebug =3;
$mail ->SMTPSecure="tls";
$mail ->Port=587;
#Connection settings
$mail ->Host= "smtp.gmail.com";
$mail ->Username="email#gmail.com";
$mail ->Password="password";
$mailTo ='email#gmail.com';
$mail-> IsHTML(true);
$mail ->SetFrom($mailFrom,$User_name);
$mail ->addAddress($mailTo);
$mail->AddReplyTo($mailFrom, $User_name);
#Create email
$mail->Subject ='I would like to come at the party ! ';
$mail->Body ="Name: $User_name<br>
Phone No: $phone<br>
City: $city<br>
Facebook: $facebook<br>
Email id: $mailFrom<br>
QrCode: $qrCode";
return $mail->Send();
}
This is my functionalities.php file (where I want to send the email):
$qrCode=create_QrCode($name);
if(!Send_email($email,$name,$phone,$city,$facebook,$qrCode))
{
echo "Mail NOT SENT";
}
else
{
echo"Mail Sent !";
}
header('Location:redirecting_page.html');
}
I have tried different modes, but I don't know how to figure it out. I know in the QRCode function, I am generating it to a file, but this is what I succesfully created until now. I know the QRCode function is the problem, but I don't know how to fix it. Can somebody please help me?
I can actually send the emails but I want to change the email from name. When I send emails, it comes into the receiver mailbox with my mail id. I want to change that to some other names. Kindly help me to do that. This is my code
<?php
$mailto = $_POST['mail_to'];
$mailSub = $_POST['mail_sub'];
$mailMsg = $_POST['mail_msg'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 0;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.gmail.com";
$mail ->Port = 465; // or 587
$mail ->IsHTML(true);
$mail ->Username = "dkdev006#gmail.com";
$mail ->Password = "password";
$mail ->SetFrom("Kreatz.in");
$mail ->Subject = $mailSub;
$mail ->Body = $mailMsg;
$mail ->AddAddress($mailto);
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
Look at the docs on this method.
You have $mail ->SetFrom("Kreatz.in");, which is neither a "nice" name nor an email address, so I don't know what you're trying to do there. You probably want to do this:
$mail ->setFrom('dkdev006#gmail.com', 'Kreatz.in');
Bear in mind that you're using gmail to send through, so you are not allowed to set arbitrary from addresses, though you can create fixed aliases in gmail prefs.
You're also using an old version of PHPMailer, and have based your code on an obsolete example, so get the latest version.
This question already has answers here:
Send email using the GMail SMTP server from a PHP page
(16 answers)
Phpmailer using smtp with Gmail not working - connection timing out
(8 answers)
PEAR Mail unable to connect to Gmail SMTP, failed to connect to socket
(9 answers)
PHPMailer with GMail: SMTP Error
(2 answers)
Closed 4 years ago.
Im trying to send an email on localhost(wamp) but it gives me the error on top!
I also tried with 'tls' and port 587 but same error
my email is configured to receive insecure connection and Imap option is activated ..
pls help me , I need this for school project
<?php
$mailto = $_POST['mail_to'];
$mailSub = $_POST['mail_sub'];
$mailMsg = $_POST['mail_msg'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail ->IsSmtp();
$mail ->SMTPDebug = 2;
$mail ->SMTPAuth = true;
$mail ->SMTPSecure = 'ssl';
$mail ->Host = "smtp.gmail.com";
$mail ->Port = 465; /* or 587;*/
$mail ->IsHTML(true);
$mail ->Username = "xxxxx";
$mail ->Password = "xxxxx";
$mail ->SetFrom("xxxxx");
$mail ->Subject = $mailSub;
$mail ->Body = $mailMsg;
$mail ->AddAddress($mailto);
if(!$mail->Send())
{
echo "Mail Not Sent";
}
else
{
echo "Mail Sent";
}
?>
I tried to change port number and 'ssl' to 'tls'. I also activated extension=php_openssl.dll in php.ini, restarted the server and allowed the low security applications on Gmail (https://www.google.com/settings/security/lesssecureapps)
These solutions seem to work for everyone but not me! can you help? here is my code:
<?php
session_start();
include 'dbConnector.php';
$toAddress = $_POST['toEmail'];
$emailSubject = $_POST['subject'];
$emailContent = $_POST['content'];
$fromPassword = $_POST['frompassword'];
require 'PHPMailer-master/class.phpmailer.php';
require 'PHPMailer-master/PHPMailerAutoload.php';
require 'PHPMailer-master/class.smtp.php';
$mail = new PHPMailer();
$mail -> IsSMTP();
$mail -> SMTPDebug = 1;
$mail -> SMTPAuth = true;
$mail -> SMTPSecure = 'ssl';
$mail -> HOST = "smtp.gmail.com";
$mail -> Port = 465; //587
$mail -> IsHTML(true);
$mail -> Username = $_SESSION['loggedUserEmail'];
$mail -> Password = $fromPassword;
$mail -> SetFrom($_SESSION['loggedUserEmail']);
$mail -> Subject = $emailSubject;
$mail -> Body = $emailContent;
$mail -> AddAddress($toAddress);
if(!$mail -> Send ())
{
echo "Your mail has not been sent!";
}
else
{
echo "Your email has been sent successfully!";
}
?>