So I'm using PHPAutoload to send an e-mail. However the mail won't send. I made a contact form where I ask for your name, subject and message and implemented that into my php code. Can anybody help me?
Thanks in advance.
<?php
include(HPHMailerAutoload);
$result="";
if(isset($_POST['submit'])){
require 'PHPMailerAutoload.php';
$mail->Host='smtp.gmail.com';
$mail->Port=587;
$mail->SMTPSecure='tls';
$mail->Username='test#test.com';
$mail->Password='******';
$mail->setFrom($_POST['email'], $_POST['name']);
$mail->addAddress('email');
$mail->addReplyTo($_POST['email'], $_POST['name']);
$mail->isHTML(true);
$mail->Subject='Test ';
$mail->Body='Test';
}
?>
You forgot to call send() so add this code after $mail->Body='Test';
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo; // you can redirect to an error page
} else {
echo 'Message sent!'; // you can redirect to a thank page
}
Related
I do not understand why two messages come to my mail.
The send function is launched once and the message about the successful sending displays once.
<?php
require('class.phpmailer.php');
$email = new PHPMailer();
$email->CharSet = 'UTF-8';
$email->From = $_POST['mailmy'];
$email->FromName = '«Тэкс»';
$email->Subject = 'Ваша новая кухня почти готова.';
$email->Body = $_POST['mailText'];
$email->AddAddress( $_POST['mailMeil']);
$email->Send();
echo 'Message has been sent';
if (!$email->send()) {
echo "Mailer Error: " . $email->ErrorInfo;
} else {
echo "Message sent!";
}
?>
You call the send() method twice:
$email->Send(); // first time
echo 'Message has been sent';
if (!$email->send()) { // second time
The code is doing exactly what you told it to do: send twice.
What you should do is store the result the first time and test that:
$sent = $email->Send();
echo 'Message has been sent';
if (!$sent) {
As an aside: your echo statement there doesn’t make sense. You shouldn’t tell the user the message has been sent if you don’t know that yet.
I'm using PHPMailer to send emails from my website but $mail->send() is returning true and mail is not sending. No error is reporting in my error log. I hosted my site in Bigrock. I didn't find any errors in my code.
<?php
if(isset($_POST['submit']))
{
require 'class.smtp.php';
require 'PHPMailerAutoload.php';
ini_set('SMTP','localhost' );
ini_set('sendmail_from', 'exmaple#gmail.com');
$fromrec=$_POST['from'];
$from="example#gmail.com";
$subject=$_POST['sf'];
$message=$_POST['message'];
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->setFrom($from, 'Rahul');
$mail->addAddress("example1#gmail.com");
$mail->Subject = $subject;
$mail->Body = "From:".$fromrec."".$message;
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else if($mail->send()) {
echo 'Message has been sent.';
echo $mail->ErrorInfo;
}
else
{
echo 'Mailer error: ' . $mail->ErrorInfo;
}
}
?>
On this issue, I have consulted Bigrock customer care and I made a chat with them. It's simple in the above code the from address email id must be domain specific and to address would be anything. After changing the email id to domain specific and Host to mail.example.com. My problem has been solved. If anyone got the same problem please try this.
I am trying to send an email with a .PDF attached using PHPMailer Master.
I am receiving no email, seeing no errors and cannot understand what's going on.
Here is my code:
$url = ''. $_SERVER['DOCUMENT_ROOT'] .'/free-quote/';
$mail = new PHPMailer;
$mail->setFrom('removed#email.com', 'Company Name');
$mail->addAddress(''. $email2 .'', ''. $full_name .'');
$mail->Subject = 'Website Quotation ('. $quotation_ref .')';
$mail->addStringAttachment(file_get_contents($url), ''. $quotation_ref .'.pdf');
$mail->Body = 'Hi! This is my first e-mail sent through PHPMailer.';
I have also included the required file:
require('PHPMailer-master/class.phpmailer.php');
Ideas?
From the PHPMailer Docs:
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
https://github.com/PHPMailer/PHPMailer
Email sends correctly, but then everything on my submission page disappears (although in the url it says it is the same page) except the echo statement saying 'Message sent successfully'.
I want to have a 'congratulations' page or something less cheesy to greet the user after they are sent the validation email...
I've tried searching the class.phpmailer.php for a redirect function but theres nothing. I'm sure its something simple but I cant seem to locate whats causing this.
<?php
require ('/config.inc.php');
require '../PHPMailer/PHPMailerAutoload.php';
if(mysqli_affected_rows($dbc) == 1){
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "censored#gmail.com";
$mail->Password = "censored";
//Set who the message is to be sent from
$mail->setFrom('censored#gmail.com');
//Set an alternative reply-to address
$mail->addReplyTo('censored#gmail.com');
//Set who the message is to be sent to
$mail->addAddress($trimmed['email']);
//Set the subject line
$mail->Subject = 'PHPMailer mail() test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML('Thank you for registering at The Circle Of Pi. To activate your account,
please click on this link:\n\n' . BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a");
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!1";
}
exit();
}else {
echo '<p class=\"error\">You could not be registered due to a system error. We apologize
for any inconvenience.</p>';
}
}else{
echo '<p class = \"error\">That email address has already been registered. If you have
forgotten your password, use the link at the right to have your password sent to you</p>';
}
} else {
echo '<p class = \"error\">Please try again.</p>';
}
mysqli_close($dbc);
}
?>
If your request is POST then you're calling exit() after 'Message sent!1' echo.
else {
echo "Message sent!1";
}
exit();
On your:
<form method="post">
Add a action to it such as:
<form method="post" action="{pickaname}.php">
and create a file called {pickaname}.php and make it when all the data is inserted it will redirect the user to your congratulations page.
I came across a bizarre issue with PHPmailer (version 5.1) that I'm trying to workaround. I've seen quite a bit of good feedback on here, so I thought I would give it a try. I've found that when I attempt to create a customized confirmation message with a conditional statement based on $mail->send(), I receive duplicate emails. I can duplicate it with the generic testemail.php script that comes with the PHPMailer download. Here's the code:
require '../class.phpmailer.php';
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
$mail->SMTPDebug = 1;
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "mail.domain.com"; // SMTP server
$mail->Username = "username"; // SMTP server username
$mail->Password = "password"; // SMTP server password
$mail->IsSendmail();
$mail->From = "example_from#domain.com";
$mail->FromName = "First Last";
$to = "example#domain.com";
$mail->AddAddress($to);
$mail->Subject = "PHP Mailer test";
$message = "This is a test. \n";
$mail->Body = $message;
$mail->Send();
if ($mail->Send()) {
echo 'Message has been sent.';
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
The above code echoes the "Message has been sent" confirmation, but then sends two emails. If I comment out the $mail->send() line, I still receive the "message has been sent" confirmation and only get one message. If I remove the conditional statement and leave the $mail->send() line commented out, no email is sent.
Why does adding a conditional statement cause an email to be sent without calling the $mail->send() method?What is the proper way of adding a customized confirmation message?
When you put $mail->Send() in your conditional, you're actually calling it again, sending another message, and checking if that second message was sent.
If you just keep
if ($mail->Send()) {
echo 'Message has been sent.';
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
and get rid of the original, unconditional Send call, you should be fine.
Alternatively, if it's clearer for you or if you need to do some processing elsewhere that depends on whether the message was successfully sent, you could do the essentially equivalent:
$status = $mail->Send();
if ($status) {
echo 'Message has been sent.';
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}