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?
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
I want to send an email with PHP script which include a gif image in it. It executed successfully(send mail with GIF Image) when I run it via browser URL, but when I run it via cron job/ schedule task it send only the mail body without GIF image.
CODE :
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
require("connectionFile.php");
$mail = new PHPMailer(true);
try
{
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'xyz.domain.com';
$mail->SMTPAuth = true;
$mail->Username = 'xyz#domain.com';
$mail->Password = 'xyz';
$mail->Port = 25;
$mail->setFrom(xyz#domain.com, 'From:test server');
$mail->addAddress('abc#domain.com');
$mail->isHTML(true);
$mail->Subject = "TEST MAIL";
$mail->AddEmbeddedImage('test1.gif', 'logo_2u');
$mail->Body = "Dear user,<br/><br/><img src='cid:logo_2u' width='500px' height='750px'/></br></br>IT IS A TEST MAIL..<br/>";
$mail->send();
echo 'Message has been sent';
$mail->ClearAllRecipients();
}
catch (Exception $e)
{
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
?>
I found that cron jobs do not set a PATH environment var by default, so I set an absolute path of image in my script. Below are the changes required :
$path='/var/usr/folder_name/test1.gif';
$mail->AddEmbeddedImage($path, 'logo_2u');
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;
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.
I'm working on a project, And i need send email after enter email and password by user. They can activate them account click that send email. But i got error when i using PHPMailer. Error was that like
Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer' not found in
C:\xampp\htdocs\E-Commerce-New-2\registration.php:20 Stack trace: #0
{main} thrown in C:\xampp\htdocs\E-Commerce-New-2\registration.php on
line 20
In new PHPMailer version use PHPMailerAutoload.php file? I think answer is no.
I tried use that code $mail = new PHPMailer\PHPMailer(); and also this code $mail = new PHPMailer(); No one is worked yet. I put my file structure down below
And here i'm past my codes lines.
<?php
session_start();
include("includes/db.php");
include("functions/functions.php");
include('PHPMailer/PHPMailer.php');
?>
<?php
// If the values are posted, insert them into the database.
if (isset($_POST['email']) && isset($_POST['password'])){
$email = $_POST['email'];
$password = $_POST['password'];
$verification_key = md5($email);
$query = "INSERT INTO `customers` (customer_pass,customer_email,verification_key) VALUES ('$password', '$email','$verification_key')";
$result = mysqli_query($con, $query);
if($result){
$mail = new PHPMailer\PHPMailer();
$mail->setFrom('noreplay#clickshop.com');
$mail->addAddress($email,'test');
$mail->Subject = "Verify Your Account";
$mail->isHTML(true);
$mail->Body = ' Please verify your email address to activate your account by clicking on this link <br>
<a href="http://localhost/E-Commerce-New-2/verify.php?key="'. $verification_key.'>Click Here</a>';
if(!$mail->send()) {
$fmsg= 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
} else {
$smsg = 'User Registration successfull. Please Check your email to Activate Account!';
}
}else{
$fmsg = "User registration failed";
}
}
?>
Can anybody give me a suggestion?
In the new PHPMailer v6.0+, you will now need to import the PHPMailer classes into the global namespace at the very top of your PHP script.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.example.com";
$mail->SetFrom("$from", "$from");
$mail->AddAddress("$to");
$mail->Subject = "$subject";
$mail->Body = "$message";
$mail->Send();