How I can show success message after to click send in my form? my phpmailer is working but I want to also after to click send to redirect to my homepage (index.html) and show my message div. This is my php code.
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.xxxxxxx.pl'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxx#xxxxxxxx.pl'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom($email, $name);
$mail->addAddress('xxxx#gmail.com', 'xxxxxxxx'); // Add a recipient // Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = 'Body test';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
header('Location: index.html');
}
And this is my Jquery code to show/hidden div succes:
$('.box-up').animate({top : 150}, 'normal').delay(3000).animate({top : -500}, 'normal');
You could send extra parameter with your request :
header('Location: index.php?r=1');
Then in your index page get the parameter and use it to show the box :
<script>
var result="<?php echo $_GET['r']; ?>";
if(parseInt(result)){
$('.box-up').animate({top : 150}, 'normal').delay(3000).animate({top : -500}, 'normal');
}
</script>
Hope this helps.
Related
I am trying to send messages from my website specialeducationnotes.co.in but not able to send the messages.
<?php
if(isset($_POST['query-submit'])) {
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
// $mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myemail#gmail.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$from = $_POST['email'];
$subject = $_POST['subject'];
$mail->From = $from;
$mail->FromName = $_POST['name'];
$mail->addAddress('specialeducationnotes1#gmail.com'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = '<h2 style="text-align: center;"s>Name: '.$_POST['name'].'<br>Email: '.$_POST['email'].'<br>Message: '.$_POST['query'].'</h2>';
$mail->AltBody = 'Hello! Hola! Namaste!';
if(!$mail->send()) {
//echo 'Message could not be sent.';
echo "<script>alert(' Your message could not be sent!');</script>";
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
//echo 'Message has been sent';
echo "<script>alert(' Your message is sent!');</script>";
echo "<script>document.location.href='index.php'</script>";
}
}
?>
I just get a blank page with no error message or any text and email is also not sent. Can you tell what's wrong with my code?
got a quick question about my contact form. When u send a message then the page reload and u coming to the header of the page. I would like to have it that you stay on the contact section when u send the message and that under the send button a text shows up like "hey, the message is send" I got in the code my homepage as link but I have a one-age site so I dont know how to fix the section that it stands on the contact section...
here is the code from the phpmailer:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.test.de'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MY EMAIL'; // SMTP username
$mail->Password = 'MY PASSWORT!'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('MY EMAIL');
$mail->addAddress($_POST['mail']); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['text'];
$mail->send();
//echo 'Message has been sent';
header('Location: http://www.example.com/contact.php');
exit();
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>
if you need the homepage to see what I mean: www.yveslumiere.com
Cheers Yves :-)
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
I am newbie and i'm trying to send mail using php but unable to send mail when i click on submit button new window open which contain some part of my php code......i want to send email from user email id to my email id with the content of form
This is the first time i'm using php and i stuck in this
<?php
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
require 'class.smtp.php';
// require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = "example#gmail.com";
$mail->Password = "example";
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = "example#gmail.com";
$mail->FromName = "ADMIN";
$mail->addAddress("example#gmail.com", "User 1");
$mail->IsHTML(true);
$mail->Subject = "form Submission";
$subject = $_POST['subject'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$name = $_POST['name'];
$company = $_POST['company'];
$city = $_POST['city'];
$message = $_POST['message'];
$mail->Body = "
<html>
<h2><br>Name: $name</br>
<br> Email: $email</br>
<br> Phone: $phone</br>
<br> Subject: $subject</br>
<br> Company: $company</br>
<br> City: $city</br>
<br> Message: $message </br></h2>
</html>";
$mail->AltBody = '';
if (! $mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
?>
html--> action="http://myIPhere:7070/projectname/sendemail.php"
please help me to resolve this problem
i'm using tomcat server 9.0
my entire php code got print i think php code is not executing
in my webcontent i added
class.smtp.php
class.phpmailer.php
class.PHPMailerAutoload.php
<?php
include "PHPMailer_5.2.4/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "test#gmail.com";
$mail->Password = "test#12#";
$mail->AddReplyTo("test#gmail.com", "test mail");
$mail->AddAddress('test#gmail.com', 'test mail ');
$mail->Body = "message:hiii";
if ($mail->send())
//if (mail($subject,$message, $headers))
{
echo "Thank you for sending mail us!";
} else {
echo "Mailed Error: " . $mail->ErrorInfo;
}
?>
this is the sample code..you can download smtp library function from github....
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers (smtp.gmail.com if you can use Gmail Account)
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#gmail.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
Use this configuration and download PHPMailer from GitHub.
https://github.com/PHPMailer/PHPMailer
i have phpmailer and i can send email via php page without any problem
but the sender automatically by username it i am use in smtp server
i want take sender email from user who write message not from default sender
and this is form code
<?php
require '../../PHPMailer/PHPMailer-master/PHPMailerAutoload.php';
$name = $_POST['name'];
$Institute = $_POST['Institute'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->Debugoutput = 'html';
//$mail->SMTPDebug = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "MyGmail";
$mail->Password = "MyGmailPass";
$mail->setFrom('Mygmail', $name);
$mail->addReplyTo('MyGmail', 'First Last');
$mail->addAddress('MyEmail', 'Nasser');
$mail->Subject = 'Database Site Reminder';
$mail->Body = ($message);
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
i am put `$mail->setFrom('Mygmail', $name); this like
$mail->setFrom($email, $name);
because take sender email from user , and i get Message sent
but message not arrive to my email
i cant find any solution... please assist me
thanks ...
$mail = new PHPMailer();
$body = "Body text goes here";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "Gmail Id"; // GMAIL username
$mail->Password = "PaSsWoRd"; // GMAIL password
$mail->SetFrom('fromemail#gmail.com', 'User');
$mail->AddReplyTo("fromemail#gmail.com","User");
$mail->Subject = "Subject Goes Here";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress('toemail#gmail.com', 'User');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo("Success");
}
try this code... its working....
If you are using PHP Mailer from Github,
then you can set the Sender name by,
$mail->SetFrom("info#mibckerala.org", "MIBC");
I am trying to let users fill out a contact form, which will then be sent to my email. But its not working for some reason. I just get a blank page with no error message or any text and email is also not sent.
if (isset($_POST['submit']))
{
include_once('class.phpmailer.php');
$name = strip_tags($_POST['full_name']);
$email = strip_tags ($_POST['email']);
$msg = strip_tags ($_POST['description']);
$subject = "Contact Form from DigitDevs Website";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "info#example.com"; // SMTP account username example
$mail->Password = "password"; // SMTP account password example
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress('info#example.com', 'Information');
$mail->AddReplyTo($email, 'Wale');
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
You need to call:
$mail = new PHPMailer(true); // with true in the parenthesis
From the documentation:
The true param means it will throw exceptions on errors, which we need
to catch.
Its working now, i didnt include the 'class.smtp.php' file. The working code is below:
if (isset($_POST['submit']))
{
include_once('class.phpmailer.php');
require_once('class.smtp.php');
$name = strip_tags($_POST['full_name']);
$email = strip_tags ($_POST['email']);
$msg = strip_tags ($_POST['description']);
$subject = "Contact Form from DigitDevs Website";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "info#example.com"; // SMTP account username example
$mail->Password = "password"; // SMTP account password example
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress('info#example.com', 'Information');
$mail->AddReplyTo($email, 'Wale');
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
I had the same problem with no error message even with SMTPDebug enabled. After searching around for working examples I noticed that I didn't include the SMTP Secure value. Try adding this line:
$mail->SMTPSecure = 'ssl'; //secure transfer enabled
Work like a charm now.
I had a similar problem. In reference to #Syclone's answer. I was using the default "tls".
$mail->SMTPSecure = 'tls';
After I changed it to
$mail->SMTPSecure = 'ssl';
It worked ! My mailserver was only accepting connections over SSL.
What worked for me was setting From as Username and FromName as $_POST['email']
Hope this helps
PHPMailer use exception.
Try this
try {
include_once('class.phpmailer.php');
$name = strip_tags($_POST['full_name']);
$email = strip_tags ($_POST['email']);
$msg = strip_tags ($_POST['description']);
$subject = "Contact Form from DigitDevs Website";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
//$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "info#example.com"; // SMTP account username example
$mail->Password = "password"; // SMTP account password example
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress('info#example.com', 'Information');
$mail->AddReplyTo($email, 'Wale');
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->Send();
exit;
} catch (phpmailerException $e) {
echo $e->errorMessage(); //error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage();
}
I was trying to load an HTML file to send, which did not belong to the www-data group on my Ubuntu server.
chown -R www-data *
chgrp -R www-data *
Problem solved!
I was debating whether to write my own handler or crow-bar PHPMailer into my existing class structure. In the event it was very easy because of the versatility of the spl_autoload_register function which is used within the PHPMailer system as well as my existing class structure.
I simply created a basic class Email in my existing class structure as follows
<?php
/**
* Provides link to PHPMailer
*
* #author Mike Bruce
*/
class Email {
public $_mailer; // Define additional class variables as required by your application
public function __construct()
{
require_once "PHPMail/PHPMailerAutoload.php" ;
$this->_mailer = new PHPMailer() ;
$this->_mailer->isHTML(true);
return $this;
}
}
?>
From a calling Object class the code would be:
$email = new Email;
$email->_mailer->functionCalls();
// continue with more function calls as required
Works a treat and has saved me re-inventing the wheel.
Try this ssl settings:
$mail->SMTPSecure = 'tls'; //tls or ssl
$mail->SMTPOptions = array('ssl' => array('verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true));