php mailer Mailer Error: Language string failed to load: connect_host? - php

I keep getting this error..
below is my code:
<?php
ini_set("include_path", "phpmailer/");
require 'phpmailer/class.phpmailer.php';
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'smtp.gmail.com';
$mailer->Port='465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = 'mail#gmail.com'; // Change this to your gmail adress
$mailer->Password = '****'; // Change this to your gmail password
$mailer->From = 'maile#gmail.com'; // This HAVE TO be your gmail adress
$mailer->FromName = 'Belmer'; // This is the from name in the email, you can put anything you like here
$mailer->Body = 'This is the main body of the email';
$mailer->Subject = 'This is the subject of the email';
$mailer->AddAddress('another#ymail.com'); // This is where you put the email adress of the person you want to mail
if(!$mailer->Send())
{
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
Anyone knows this error? Your reply is greatly appreciated.

Got it! Thanks guys for viewing.
There's actually no problem with the code, it has to be some settings on my local server. My solutions is i uploaded the files to my live webserver and everything is working fine.

Related

PHPMailer and Gmail smtp, not getting sent or failed message

Instead of using php's mail() function, I've been trying to set up PHPMailer with no success. I put in "echo here" for debugging purposes, and that is all it shows. I do not get any emails, or the sent or error messages. I'm stumped, and after researching it on here may switch to swift mailer. I'd really like to know what I screwed up though.
In my code, address is set to my email, and the username and password are set to a dummy account I made.
<?php
include('class.phpmailer.php');
$mail = new PHPMailer();
$address = "test#gmail.com";
$body = "test email";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "username#gmail.com";
$mail->Password = "password";
$mail->SetFrom('name#yourdomain.com', 'Web App');
$mail->Subject = "A Transactional Email From Web App";
$mail->MsgHTML($body);
$mail->AddAddress($address, $name);
echo "Here";
if($mail->Send()) {
echo "Message sent!";
}
else {
echo "Mailer Error: " ; $mail->ErrorInfo;
}
?>
As you are using Gmail I think you must make sure the gmail account has the insecure application auth activated

PHP Mailer - Internal Server Error

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.

Catchable fatal error using PHPMailer

I am trying to create an email confirmation when registering in a page. and i am receiving this error when submiting it.
Catchable fatal error: Object of class PHPMailer could not be converted to string in C:\wamp\www\includes\reg.php on line 90
and here is my code,
<?php
session_start();
require '../class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; // "ssl://smtp.gmail.com" didn't worked
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$email = $_POST['email'];
$mail->Username = "XXX#gmail.com";
$mail->Password = "XXX";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
$mail->From = "XXX#gmail.com";
$mail->FromName = "Your Name";
$mail->addAddress("XXX#live.com","User 1");
$mail->addAddress($email,"User 2");
$mail->addCC("user.3#ymail.com","User 3");
$mail->addBCC("user.4#in.com","User 4");
$mail->Subject = "Confirm your Account!!";
$mail->Body = "Confirm Your Email, Click link to verify your account,,<br /><br />http://localhost/includes/emailconfirm.php?email=$_POST[email]&code=$mail";
if(!$mail->Send())
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";
header('refresh: 0; url=../index.php#openModal');
$message = "You are now Registered, Please Sign In.";
echo("<script type='text/javascript'>alert('$message');</script>");
}
?>
this one was the line getting the error,
$mail->Body = "Confirm Your Email, Click link to verify your account,,<br /><br />http://localhost/includes/emailconfirm.php?email=$_POST[email]&code=$mail";
and I dont know if using $email works, i need to send email to the email the user has submitted. please help thank you.
Look at the end of the line with error where you have &code=$mail";. You previously defined $mail as PHPMailer, where probably this class doesn't provide __toString() function.
__toString() is a magic function which is called upon when the object has to be converted to string. In your situation, when $mail (a PHPMailer object) has to be inserted as a concatenation in a string, it tries to call __toString() but none is provided.
Instead of using $mail->Body = "Confirm Your Email, Click link to verify your account,,<br /><br />http://localhost/includes/emailconfirm.php?email=$_POST[email]&code=$mail";
try using $message = "Confirm Your Email, Click link to verify your account,,<br /><br />http://localhost/includes/emailconfirm.php?email=$_POST[email]&code=$mail";
then $mail->Body = $message;

PHP Mailer Error: Mailer Error - must provide at least one recipient email address

I'm having and an issue with php mailer script. Using mamp the script works, but on the server I get an error (I've omitted sensitive info).
"Invalid address: [valid email] Mailer Error: You must
provide at least one recipient email address."
Heres my code:
require_once("includes/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.emailsrvr.com";
$mail->SMTPDebug = 2;
$mail->Port = 25;
$mail->Username = "test#test.com";
$mail->Password = "test";
$mail->Subject = "Subject";
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->AddReplyTo($_POST['email'], $_POST['name']);
$address = "test#test.com";
$mail->AddAddress($address, "name");
$body = "<p>test</p>";
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
If it helps, I am using the rackspace email apps.
Im not very savy with php or server setups unfortunately so if anyone can help that would be great!
Just change this line:
$address = "[valid email]";
to something like:
$address = "test#test.te";
or to your own email, so you can test better, and it will work.
It's just stating that '[valid email]' is not actually a "valid email".
So i had no luck here, but I now know the issue stems from server mail settings rather then the script.
In the end I just went to using postmark.
I face this issue when my class name and my function name is same. Than i change the name of the function and it was resolved. Hope it will help anyone.

phpmailer not sending email

i am using phpmailer and i am getting following error:
Message was not sent
Mailer Error: SMTP Error: Could not connect to SMTP host.
<?php
require("class.phpmailer.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.myhost.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = 'myemail#myhost.com';
$mailer->Password = 'mypass';
$mailer->From = 'myemailagain#myhost.com';
$mailer->FromName = 'myname';
$email1 = $_GET['email'];
$verification = rand();
$mailer->Body = 'Welcome to our site';
$mailer->Subject = 'verification';
$mailer->AddAddress($email1);
if(!$mailer->Send())
{
echo "Message was not sent<br/ >";
echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
note: i use "myhost.com" but it's not my real domain
I believe you are specifying your host incorrectly. Try this instead:
$mailer->Host="smtp.myhost.com";
$mailer->Port=465;
$mailer->SMTPSecure="ssl"; //If this doesn't work, try 'tls'
If it still doesn't work, consider setting:
$mailer->SMTPDebug=1;
Also, make sure PHP's OpenSSL extension is enabled.

Categories