I have a basic php emailer codes. I tried it on my personal site.It works very well.My site host is like ;
$mail->Host =mail.mysite.com
And i tried it another site, and of course i change the other values that needed,it doesnt work and i get this error : language string failed to load :connect host .
Also this site have a host like this : ***.secureserver.com . (not like mail.mysite.com)
I thought this error should about hosting and called the host company,they told me everything is ok about host,the code is wrong.
I try to find a solution,i hope somebody help
function mail_gonder($isim,$mesaj,$konu,$eposta)
{
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "*****.server.net";
$mail->SMTPAuth = true;
$mail->Username = "noreply#***.com";
$mail->Password = "****";
$mail->From = "noreply#****.com";
$mail->Fromname =$isim; //
$mail->AddAddress($eposta,$konu);
$mail->Subject =$konu;
$mail->Body = $mesaj;
if(!$mail->Send())
{
echo '<font color="#F62217"><b>Gönderim Hatası: ' . $mail->ErrorInfo . '</b></font>';
exit;
}
echo '<font color="#41A317"><b>Mesaj başarıyla gönderildi.</b></font>';
}
The fix for this is actually simple, set the language to this:
$mail = new PHPMailer();
$mail->SetLanguage("en", 'includes/phpMailer/language/');
Make sure the files you have are all local. Make sure you uploaded the files to your live webserver. Some servers are setup not to allow some type of connections to external resources. Uploading the files to your own server have been known to fix this.
Related
I'm trying to send an email with PHPMailer, but it's not working for me so far.
On my FTP I've put 2 files, the class.phpmailer.php and sendEMail.php (this file is created by me), with this content:
<?php
require_once('/var/www/vhosts/MYWEBPAGE/httpdocs/class.phpmailer.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "mail.dom.com";
$mail->Username = "smpt#mail.com";
$mail->Password = "passwd";
$mail->Port = 25;
$mail->setFrom("my#mail.com", "me", 0);
$mail->addAddress("to#mail.com");
$mail->Subject = "test";
$body = "Hello World!";
$mail->Body = $body;
if(!$mail->send()) {
echo ("Invoice could not be send. Mailer Error: " . $mail->ErrorInfo);
} else {
echo "Invoice sent!";
}
?>
I'm missing something? When I execute this file, it shows me nothing, i mean before the if(!$mail->send()) {... It shows me every echo, but after that line, it shows me nothing.
It's because you've not read the readme that tells you what files you need, nor based your code on the examples provided. You've not loaded the SMTP class, nor the autoloader that will load it for you, so as soon as you try to send, it will fail to find the SMTP class. This will be logged in your web server logs like any other PHP fatal error.
Instead of this:
require_once('/var/www/vhosts/MYWEBPAGE/httpdocs/class.phpmailer.php');
do this:
require '/var/www/vhosts/MYWEBPAGE/httpdocs/PHPMailerAutoload.php';
I've had a look around as to why my PHP script was not sending any emails when I had the $mail->isSMTP(); set.
Before I go into the problem, I would like to point out that I am using mailgun.org as my SMTP server. My PHP script is simple, I have an HTML form that forwards data to a PHP file which in turn calls the PHPMailer script and sends an email.
Here is the code to my PHP Script:
date_default_timezone_set('Asia/Manila');
require 'phpmailer/PHPMailerAutoload.php';
// include 'phpmailer/class.phpmailer.php';
// require 'phpmailer/class.smtp.php';
$mail = new PHPMailer;
//$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = "smtp.mailgun.org";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = ""; //Username removed
$mail->Password = ""; //Password removed
$mail->setFrom('', ''); //Email address and Name removed
$mail->addReplyTo($userMail, $firstName);
$mail->addAddress('emailOne#example.com', 'Name'); //Actual Values Changed
$mail->addAddress('emailTwo#example.com', 'Name'); //Actual Values Changed
$mail->addAddress('emailThree#example.com', 'Name'); //Actual Values Changed
$mail->Subject = 'New Application for website by '. $firstName;
$mail->msgHTML($theMessage);
$mail->AltBody = $theMessage;
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else { //Some HTML code here
}
Now then, as you can see, I have commented out the $mail->isSMTP(); line. This is because whenever I try to use it, the code does not load, and after a long wait gives a 500 error. (Sadly, by cPanel setup does not allow me to view apache logs).
I tried importing just the class.phpmailer.php file, but that gave me a fatal error that the class SMTP was not defined, which was expected. I then included the class.smtp.php file which gave me the same 500 error.
I had a look around StackOverflow and came across this answer however it did not help my case.
I have had a look at Mailgun's logs, but they have no record of the script even trying to connect.
Additional Information: If it matters, I have the following files in the same directory:
- sendMail.php //The script above
- class.phpmailer.php
- class.smtp.php
- PHPMailerAutoload.php
- index.html //Not important in this situation.
I hope someone will be able to help me out, I'm relying on the non-smtp method for now. :/
Try this working fine..!
date_default_timezone_set('Asia/Manila');
require 'phpmailer/PHPMailerAutoload.php';
// include 'phpmailer/class.phpmailer.php';
// require 'phpmailer/class.smtp.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = ""; //Username removed
$mail->Password = ""; //Password removed
$mail->addReplyTo($userMail, $firstName);
$mail->SetFrom('emailOne#example.com', 'my name');
$mail->Subject = 'New Application for website by '. $firstName;$mail->MsgHTML($theMessage);
$mail->AddAddress('aswad#yahoo.com', 'my name');
if($mail->Send()) {
echo "Message sent!";
}else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
I have been trying to make the contact form on my website to work and I've spent weeks trying to figure it out and I couldn't.
Here's the problem - I purchased a web template and it came with the PHPMailer. I'm now done plugging my content into the template, but the contact form has been a pain. I've followed the instructions the best I know on the PHP file, but it's giving me an "Internal Server Error" when I am testing the contact form.
Here's the code that came with my purchase:
$name = trim($_POST['name']);
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$site_owners_email = 'name#mydomain.com'; // Replace this with your own email address
$site_owners_name = 'My Name'; // Replace with your name
try {
require_once('/Beta-BRC/php/PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
$mail->From = $email;
$mail->FromName = $name;
$mail->Subject = "[WEB Form] ".$subject;
$mail->AddAddress($site_owners_email, $site_owners_name);
$mail->Body = $message;
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com"; // Replace with your SMTP server address
$mail->Port = 465;
$mail->SMTPSecure = "SSL";
$mail->SMTPAuth = true; // Turn on SMTP authentication
$mail->Username = "name#mydomain.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
//echo "true";
if($mail->Send()) {
echo "true";
} else {
echo "Error sending: " . $mail->ErrorInfo;
}
} catch (Exception $e) {
echo $e;
}
Quick note - I've alrealy tried using a GMAIL account on this part but it still does not work.
$mail->Username = "name#mydomain.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
There's no need to log into Gmail with phpmailer. Below is an example of my phpmailer function using the default settings.
public function sendEmail($toaddress,$toname,$subject,$message){
if($template = file_get_contents('/home/username/domains/mydomain.com/public_html/html/email-template.html')){
$template = str_replace("[SUBJECT]",$subject,$template);
$template = str_replace("[CONTENT]",nl2br($message),$template);
$mailer = new PHPMailer;
$mailer->XMailer = "Organization Name 4.0.0";
if($this->is_logged_in()){
$mailer->AddCustomHeader("X-Originating-User-ID",$this->acct['id']);
}
$mailer->AddCustomHeader("X-Originating-IP",$_SERVER['REMOTE_ADDR']);
$mailer->setFrom("outbound#mydomain.com","From Name");
$mailer->AddAddress($toaddress,$toname);
$mailer->Subject = $subject;
$mailer->MsgHTML($template);
$mailer->AltBody = $message;
return $mailer->Send();
}else{
return false;
}
}
The email address listed doesn't actually exist. The email is just being sent from my server and phpmailer just says it's from that email address.
Try modifying my function to suit your needs and let me know how that works.
Note: You'll need to make sure your mail server is turned on for this to work
Although you don't have to use my function at all. Try debugging your code by checking some error logs on your server. Typically in the apache error logs (if you're running apache, however). Checking error logs is a huge part of troubleshooting your code and often can help you become more proactive.
I hope this helps even the slightest!
The specific cause of the Internal Server Error is the incorrect path you've supplied to the require_once statement that loads the PHPMailer class.
The path you've supplied is /Beta-BRC/php/PHPMailer/class.phpmailer.php, where the correct statement should be
require_once('/home/trsta/public_html/Beta-BRC/php/PHPMailer/class.phpmailer.php');
or perhaps more generally:
require_once($_SERVER['DOCUMENT_ROOT'].'/home/trsta/public_html/Beta-BRC/php/PHPMailer/class.phpmailer.php');
You've provided effectively a URL, but PHP requires the path in the server file system, which is not the same.
That should get you past this error. It's possible that there are others.
I am having a unique issue (I did a thorough search on SO before I attempted to ask this question.
When I use the PHPMailer to send to a gmail (or hotmail, etc) address, it works great. As soon as I change it to send to a Google Apps email address, I don't get any error message instead it tells me it was successfull but no emails come through.
Has anybody seen this issue before? Is my code missing something very particular that makes it a valid email to pass through Google Apps Servers (not sure if I am heading in the right direction here). Thank you!
Start of my Code:
<?php
require("/PHPMailer_5.2.0/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Port = 465;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->Mailer = 'mail';
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = "******#dynamicsafetyfirst.com";
$mail->Password = "*******";
$mail->From = $_POST['email'];
$mail->AddAddress("someuser#gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->WordWrap = 50;
$mail->FromName = $_POST['name'];
$mail->Subject = $_POST['enquiry'];
$mail->Body = $_POST['comments']. "--By--".' name: '. $_POST['name']."--". 'email: ' .$_POST['email'];
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
END OF CODE.
You're putting in quite a lot of effort to do things wrong. First up you're using a pretty old version of PHPMailer - go get the latest from github. Next, your code has many issues, so start again using the gmail example provided. Use tls on port 587. Do not set Mailer - you've already called isSMTP(), and overriding Mailer later is asking for trouble.
To see what is going on set $mail->SMTPDebug = 3;, and it will show you the whole SMTP conversation. At that point you may get some clue as to what is happening to your message.
I am trying to use the following code to send an email from a WordPress plugin
include_once(ABSPATH . WPINC . '/class-phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->ContentType = 'text/plain';
$mail->IsHTML(false);
$mail->SetFrom(($enquiry_informations['display_email_address']!="")?$enquiry_informations['display_email_address']:"", "Autoquote");
$mail->AddAddress($customer_email_address, $customer_email_name);
$mail->Subject = $enquiry_informations['enquiry_autoresponse_subject'];
$mail->Body = $autoresponse_msg;
if($enquiry_informations['enquiry_autoresponse_attachment']!==NULL&&$enquiry_informations['enquiry_autoresponse_attachment']!==""){
$mail->addAttachment(plugin_dir_path(__FILE__) . "attachments/" . $enquiry_informations['enquiry_autoresponse_attachment']);
}
$info = $mail->Send();
if($info){
echo "Sent";
}else{
echo "Failed";
echo $mail->ErrorInfo;
}
however, I receive the following error:
The following From address failed: root#localhost : Called Mail() without being connected.
I did a little bit of googling and found out it could be something to do with protocol. This is from a wordpress plugin so I would like the code to be flexible(so that it can be used anywhere. So the varying protocol cannot get into the way.)
You did not pass all necessary values when using it. When you use isSMTP() method you have to provide the following information also:
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
Read here how to use the class properly.
I think the best way around is to use the mail helper within Wordpress.
http://codex.wordpress.org/Function_Reference/wp_mail
The error is probably caused because you are missing the right SMTP configuration, I don't know and couldn't find how you can adapt the Wordpress configuration though..
Hoping this helps you out a little!