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.'
Related
I am sending an email through PHPMailer, the code is hosted on hostinger's hpanel and I am using an email I created on the hpanel. After running the code, I get no errors, and no feedback on whether the mail has been sent, it just doesn't show anything.
Please help me I currently don't know what to do.
require '../../vendor/autoload.php';
$mail = new PHPMailer(true);
try
{
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtp.titan.email';
$mail->SMTPAuth = true;
$mail->Username = 'admin#hostinger.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'SSL';
$mail->Port = 465;
$mail->setFrom('admin#hostinger.com', 'Hostinger');
$mail->addAddress($email, $username);
$mail->addReplyTo('admin#hostinger.com', 'For any Information');
$mail->addCC('admin#hostinger.com');
$mail->isHTML(true);
$mail->Subject = 'Sending message';
$mail->Body = $message;
$mail->AltBody = "Hello there";
$mail->send();
echo "Sent";
}
catch (Exception $eax)
{
echo 'EMAIL SENDING FAILED. INFO: '.$mail->ErrorInfo;
}
No need to Use
$mail->isSMTP();
Comment $mail->isSMTP();
Make sure you are using the right smtp host:
$mail->Host = 'smtp.hostinger.com'
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 am using gmail smtp server on my website to send email when users register but currently I can not send emails all information is correct. How can I fix this issue? I am using php mailer
function send()
{
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'example#gmail.com';
$mail->Password = 'mypassword';
$mail->From = 'noreply#example.com';
$mail->FromName = 'example';
$mail->AddAddress($this->_tpl_vars['TO']);
if (isset($this->_tpl_vars['CC']))
{
$cc = explode(';', $this->_tpl_vars['CC']);
foreach ($cc as $c)
if (!empty($c))
$mail->AddCC($c);
}
$mail->AddReplyTo('noreply#example.com');
$i = array();
$i = 3;
$mail->IsHTML(true);
$mail->Subject = $this->_tpl_vars['SUBJECT'];
$mail->Body = $this->_tpl;
#$mail->Send();
}
I see message in my gmail account one user try login with my ip server gmail block it.
Thank you.
You can go to https://www.google.com/settings/security/lesssecureapps
and turn on "Access for less secure apps"
The proper way now: you may want to check https://developers.google.com/gmail/xoauth2_libraries for PHP examples on how to do it using Oauth2
I'm looking to make a contact form send to more than 1 address. currently the code is
$to = 'email#email.com';
Further down the code is
function xmail($to,$subject,$message,$headers){
global $usesmtp,$smtphost,$smtpport,$smtpuser,$smtppass,$smtpsecure,$_POST;
if($usesmtp!=1){
if(#mail($to,$subject,$message,$headers)){
return 1;
}
}else{
require_once('mail/class.phpmailer.php');
$mail = new PHPMailer();
$body =$message;
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = $smtpsecure;
$mail->Host = $smtphost;
$mail->Port = $smtpport;
$mail->Username = $smtpuser;
$mail->Password = $smtppass;
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, "Administrator");
if($mail->Send()) {
return 1;
}
}
}
Can anyone help please?
Changed
$to = 'email#email.com';
To
$to = 'email#email.com, email2#email2.com';
I'm using phpmailer to send email. But all of my emails are send with noname attachement. I already checked if variables are set before I use addAttachemnt function and they are. It looks like this:
$fname = $_FILES['file']['name'];
$fTmpName = $_FILES['file']['tmp_name'];
$mail = new PHPMailer();
$mail->From = "mymail#mymail.com";
$mail->FromName = "mymail.com"; //moje meno
$mail->IsHTML(true);
$mail->IsSMTP();
$mail->Host = "smtp.mymail.com";
$mail->Subject = "Subject";
$mail->AddAddress($email);
echo $fnameZivotopis;
$mail->AddAttachment($fTmpName,$fname);
$mail->Body = $msg;
$mail->Send(); // send message
Try to use AddStringAttachment(string $att_file_data, string $att_file_name, ...).