I've got this php code to send the users information from the contact form to my email address, but i don't know how to send a confirmation email back to the user when he fills out the form.
<?
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$areacode_telephone = $_REQUEST['areacode_telephone'] ;
$telephone = $_REQUEST['telephone'] ;
$email = $_REQUEST['email'] ;
$notes = $_REQUEST['notes'] ;
$body = " Name: ".$name."\n
Company: ".$company."\n
Area Code: ".$areacode_telephone."\n
Telephone: ".$telephone."\n
Email Address: ".$email."\n
Notes: ".$notes;
mail( "info#axsiom.com.au", "Axsiom: Contact Us", $body, "From: $email" );
?>
You are just reusing the same variables in a different combination using the same function just to send it back to them.
mail( $email, "Thank You", "We Have Recived Your Request blablabla", "From: info#axsiom.com.au" );
Tada.
To send the same message to both you and them use:
<?php
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$areacode_telephone = $_REQUEST['areacode_telephone'] ;
$telephone = $_REQUEST['telephone'] ;
$email = $_REQUEST['email'] ;
$notes = $_REQUEST['notes'] ;
$body = " Name: ".$name."\n
Company: ".$company."\n
Area Code: ".$areacode_telephone."\n
Telephone: ".$telephone."\n
Email Address: ".$email."\n
Notes: ".$notes;
mail( "info#axsiom.com.au, $email", "Axsiom: Contact Us", $body, "From: $email" );
?>
To send a different message to both you and them use:
<?php
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$areacode_telephone = $_REQUEST['areacode_telephone'] ;
$telephone = $_REQUEST['telephone'] ;
$email = $_REQUEST['email'] ;
$notes = $_REQUEST['notes'] ;
$body = " Name: ".$name."\n
Company: ".$company."\n
Area Code: ".$areacode_telephone."\n
Telephone: ".$telephone."\n
Email Address: ".$email."\n
Notes: ".$notes;
//to you
mail( "info#axsiom.com.au", "Axsiom: Contact Us", $body, "From: $email" );
//to them
mail( $email, "Thank You", "We Have Recived Your Request blablabla", "From: info#axsiom.com.au" );
?>
To send email:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$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 = 'user#gmail.com'; // Your gmail username
$mail->Password = 'your_gmail_password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'from#example.com'; // from email address
$mail->FromName = 'User1'; // whatever is the name of sender
$mail->addAddress($_POST['email'], $_POST['username']); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message ;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
Related
I designed my website and hosted on my amazon ec2 instance and I bought my domain in godaddy (www.mydomain.com).Now I want a mail configuration in my contact form page in website.. Below its my code , I don't know where am I mistake the code?
<?php
if(isset($_REQUEST['submit'])) {
try {
$name = $_POST['name'];
echo "<script type='text/javascript'>alert('$name')</script>";
$email = $_POST['email'];
echo "<script type='text/javascript'>alert('$email')</script>";
$subject = $_POST['subject'];
echo "<script type='text/javascript'>alert('$subject')</script>";
$message = $_POST['message'];
echo "<script type='text/javascript'>alert('$message')</script>";
$response ="";
$body ="<div style='font-size:18px'>
<b>Name</b> : $name <br />
<b>Email address</b> : $email <br />
<b>Message</b> : $message <br />
</div>"
$to = "XXXXX#gmail.com";
require_once($_SERVER['DOCUMENT_ROOT'].'/samplemail/lib/class.phpmailer.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/samplemail/lib/class.smtp.php');
$mail = new PHPMailer(true);
//$mail->Host = "relay-hosting.secureserver.net"; // your SMTP Server
// echo $res;
$mail->IsSMTP();
$mail->Host = "email-smtp.us-east-1.amazonaws.com";
$mail->SMTPDebug = true;
$mail->SMTPAuth = true; // Auth Type
$mail->Port = 25;
$mail->IsSendmail();
//$mail->SMTPSecure = "ssl";
$mail->Username = "support#mydomain.com";
$mail->Password = "******";
$mail->Sender = "supportexample#mydomain.com";
$mail->From = "supportexample#mydomain.com";
$mail->AddReplyTo($email);
$mail->FromName = "Example";
$mail->AddAddress($to);
//$mail->AddAddress("desired recipient no.2 optional");
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->WordWrap = 50;
If($mail->Send()){
echo "<script type='text/javascript'>alert('Mail Send Successfully')</script>";
}
} catch (phpmailerException $e) {
echo "<script type='text/javascript'>alert('Failed')</script>";
echo $e->errorMessage();
}
}
?>
I got this error. How do solve this issue?
Could not execute: /var/qmail/bin/sendmail
You can't call random functions and expect it to all work magically.
You're setting up for SMTP with isSMTP(), but then ignoring all that by calling isSendmail(), when it looks like your server simply isn't set up for it. Why do that? Re-enable isSMTP and configure your script for your mail server correctly.
You're also requesting auth while disabling encryption; that's likely to fail on any modern server.
You're also using an old version of PHPMailer, and you've based your code on an obsolete example. Get the latest, and base your code on the examples provided.
I want to send mail using phpmailer from localhost XAMPP using SMTP server (gmail). But I keep getting this error:
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I tried many solutions regarding uncomment openSSL in php.ini file, changing the port 465("ssl") and 587("tls"), but it does not work.
My codes:
<?php
date_default_timezone_set('Etc/UTC');
'PHPMailerAutoLoad.php';
class.phpmailer.php if not already loaded
$port =465;
$securetype = 'ssl';
$from = 'myemail#gmail.com';
$name = 'User';
$toemail= "mymail#gmail.com";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->isSMTPDebug = 1;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail#gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = $securetype;
$mail->Port = $port;
$mail->From = $from;
$mail->FromName = $name;
$mail->addAddress($toemail);
$mail->isHTML(true);
$mail->Subject = 'Test Mail Subject!';
$mail->Body = 'This is SMTP Email Test';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
You will need class.phpmailer.php. If you're using SMTP, you'll need class.smtp.php.
Try this demo code:
<?php
require 'class.phpmailer.php';
require 'class.smtp.php';
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
#require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'mail.domain.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 25;
//Set the encryption system to use - ssl (deprecated) or tls
//$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "demo#domain.com";
//Password to use for SMTP authentication
$mail->Password = "password";
//Set who the message is to be sent from
$mail->setFrom('demo#domain.com', 'subillion');
//Set an alternative reply-to address
#$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress("example#gmail.com");
//Set the subject line
$mail->Subject = 'Demo !!';
//Read an HTML message body from an external file, convert referenced images to embedded,
$mail->isHTML(true);
$msgbody = "This is a demo test !";
$mail->Body = $msgbody;
//send the message, check for errors
if (!$mail->send()) {
// echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
I have a simple contact form that works if I do not use smtp. I've tried to add smtp to use with mandrill, but it doesn't work. Emails aren't going through to mandrill.
I do not see any errors after sending either even if I enabled '$mail->SMTPDebug = 1;' I've tried on both local and live server environments.
<?php
require_once('../mail/class.phpmailer.php');
$emailaddress = "name#domain.com";
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$ip = $_SERVER['REMOTE_ADDR'];
$message = $_POST['message'];
$subject = "Contact Form: $name";
$body = "You have received a new message from website.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nIP Address: $ip\n\nMessage:\n$message";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.mandrillapp.com";
//$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Host = "smtp.mandrillapp.com";
$mail->Port = 587;
$mail->Username = "username";
$mail->Password = "password";
$mail->CharSet = 'UTF-8';
$mail->SetFrom($email_address);
$mail->AddReplyTo($email_address);
$mail->Subject = "Contact Form: ".$_POST['name']." ";
$mail->MsgHTML($body);
$mail->AddAddress($emailaddress);
$mail->Send();
?>
I figured it out. I needed to also include the 'class.stmp.php' file as well. It doesn't have to be call, but needs to in the same folder as 'class.phpmailer.php.'
I am trying to create a PDF file using FPDF and send it via e-mail using PHPMailer. It did send the file, but for some reasons I cannot open the file, either from my email or using Adobe Reader (which gives me something like the file is damaged).
This is my code
require('fpdf.php');
require 'PHPMailerAutoload.php';
header("Access-Control-Allow-Origin: *");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','UB',28);
$pdf->Cell(0,10,"My Profile",0,1,'C');
$pdf->Ln();
$mail = new PHPMailer();
$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 = 'example#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
// no more headers after this, we start the body! //
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
$pdfdoc = $pdf->Output('','S');
$attachment = chunk_split(base64_encode($pdfdoc));
//Set who the message is to be sent from
$mail->setFrom('example#gmail.com', 'Baby Diary');
//Set who the message is to be sent to
$mail->addAddress('example2#gmail.com', 'haha');
//Set the subject line
$mail->Subject = 'PHPMailer mail() test';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AddStringAttachment($attachment, 'doc.pdf', 'base64', 'application/pdf');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
It does give me output when I use $pdf->Output(), which hints to me that the problem should not be in FPDF side. Any suggestion will be much appreciated.
Your problem is with phpmailer and not with fpdf. Try using the standard PHPMailer class methods.
If I was you I'd try to rework your code from the attachement example included in the PHPMailer doc samples. And particularly I'd stick to using the PHPMailer methods rather that doing my own smtp formating.
So first save your pdf to file, and then try attaching the file with $mail->addAttachment() . And let PHPMailer handle the formating of the mail.
So you might end up with something like this code below (I haven't run it, you'll probably need to fine tune it) :
require('fpdf.php');
require 'PHPMailerAutoload.php';
header("Access-Control-Allow-Origin: *");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','UB',28);
$pdf->Cell(0,10,"My Profile",0,1,'C');
$pdf->Ln();
$pdfoutputfile = '/some-tmp-dir/temp-file.pdf';
$pdfdoc = $pdf->Output($pdfoutputfile, 'F');
// We're done with the pdf generation
// now onto the email generation
$mail = new PHPMailer();
$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 = 'example#gmail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
$separator = md5(time()); // a random hash will be necessary to send mixed content
//Set who the message is to be sent from
$mail->setFrom('example#gmail.com', 'From Test address');
//Set who the message is to be sent to
$mail->addAddress('example2#gmail.com', 'to test address');
//Set the subject line
$mail->Subject = 'Test message with attachement';
$mail->Body = 'Test message with attached files.';
$mail->AddAttachment($pdfoutputfile, 'my-doc.pdf');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I have a email form for my website but here is the issue: when i receive an email, the subject line in my inbox shows whatever the user inputted as subject in the form. id like to override that so that whenever an email comes in. the subject in the email header is always "an inquiry from your website". In the message body, sure i don't mind their specific subject they entered but when I receive an email, id like consistency in my inbox.
this is the current code:
<?php session_start();
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'xxxxxxxxx';
$fromsubject = 'An inquiry from your website';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $nome <$mail>\r\n";
$to = $youremail;
$mailsubject = 'Message received from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$fname.' '.$lname.'
Address: '.$address.'
'.$city.', '.$zip.', '.$country.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Subject: '.$subject.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you for inquiring. We will contact you shortly.<br/>You may return to our <a href='/index.html'>Home Page</a>";
mail($to, $subject, $body, $headers);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, you have provided an invalid security code';
}
} else {
echo "You must write a message. </br> Please visit our <a href='/contact.html'>Contact Page</a> and try again.";
}
?>
It appears as though you have set a variable called $subject elsewhere.
$subject = $_POST['subject'];
and then use that same variable to send your mail.
mail($to, $subject, $body, $headers);
Try creating another variable for the second use or changing it prior to suit your needs.