PHPMailer not sending when changed internet connection - php

I just wanna clear out. This Code is Working. But somehow I have a problem. I'm just a university student and I'm including this phpmailer for my email verification in the registration part of my project. In my house, this code is working. But, when I move to our university about one city away, the php mailer is now failing to send Email and it says "SMTP error()". My friends guess that since I moved location and changed internet connection, the error might be with the HOST and PORT. Is there any other way to make PHPMailer working without regards to my IP address, or my location, or my internet connection??
I can't see the answer within the link
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
As I said before, this code used to work already. It's just that it does not function if I move to other location or other internet connection.
I hope somebody can help me with regards to this matter.
I guess it's within the PORT and HOST.
This is my code:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "cspgryffindor#gmail.com";
$mail->Password = "cspgryffindor123";
$mail->setFrom('cspgryffindor#gmail.com', 'CSPGryffindor');
$to=$email;
$mail->From = "no-reply#web.com";
$mail->AddAddress($to);
$mail->AddReplyTo("no-reply#web.com","no-reply");
//$subject = "this is s1ubject";
//$msg="this is msg";
$mail->Subject = $subject;
$mail->Body = $message;
$mail->WordWrap = 150;
if(!$mail->send())
{
// echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
// echo "Message has been sent successfully";
}

Your new provider may have blocked the SMTP port, some of them do to prevent spam.
You should check on their FAQ if they do.
Unrelated but if your password is really cspgryffindor123, now is a good time to change it

This could be your university blocking all SMTP connections like mine did.
To find out, try using your mobile connection or another connection other than your university connection. If it's working in your home, it should be with a regular connection.

Related

Why won't this PHP Email Script send to my Yahoo email?

so I have this script and I've been trying to figure out why it won't send to my Yahoo email account.
<?php
require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
require 'autoload.php';
//PHPMailer Object
$mail = new PHPMailer(true);
$mail->SMTPDebug = 2;
$mail->Host = "tampabaydowns#tbdseats.com";
$mail->SMTPAuth = true;
$mail->Username = "tampabaydowns#tbdseats.com";
$mail->Password = "~~~";
$mail->SMTPSecure = "SSL";
$mail->Port = 465;
$mail->From = "tampabaydowns#tbdseats.com";
$mail->FromName = "Tampa Bay Downs";
$mail->addAddress("~~#yahoo.com", "Austin");
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->Body = 'This is a plain text';
try {
$mail->send();
echo "Message has been sent successfully";
} catch (Exception $e) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
When I load the script page it says sent successfully but on the server, the email bounces back with this
~~#yahoo.com
host mta6.am0.yahoodns.net [67.195.~~]
SMTP error from remote mail server after pipelined MAIL FROM:<~~~#server.tbdseats.com> SIZE=1759:
553 5.7.2 [TSS09] All messages from 217.~~ will be permanently deferred; Retrying will NOT succeed. See https://postmaster.verizonmedia.com/error-codes
I am unsure why this isn't working. When I replace my yahoo email with my gmail, it sends and my gmail gets the email from the server. Is there something different that has to be done with Yahoo?
My Yahoo email isn't blocking any incoming email addresses and it isn't in my spam.
I added ~~~ to the secure information, that is why that is there.
Can someone please help, I've been trying to figure this out for the past 3 hours :( :(
The IP address of your provider's email server is blocked by yahoo. Use another server or service to relay your messages. As you pointed out gmail is relaying your messages correctly.
You can also ask your email admin to try fix it for you, but Yahoo is difficult to deal with on this kind of errors.

PHP mail function not working in godaddy account [duplicate]

I'm using godaddy for hosting my site and using default godaddy mail service.
Now i want to sent email using php mail function to other email address from my 1 of my 15 email address of my godaddy's email accounts
How can i fix that from which email address email will be sent and how to place the username and password for the email address ?
Thanks
The PHP mail function uses the mailserver configured for that webhost. You can't change that. Since godaddy controls the mailserver they control what headers it sends. You could try inserting a custom From header but I doubt that will work. It will either get modified, flagged as spam, or rejected.
If you have 15 accounts at godaddy, perhaps it's time to look for a more serious hosting solution?
Instead of using the mail() function, which just calls the OS mail function (i.e. sendmail), try something like SwiftMail (free PHP mail library). It support many different ways of sending mail, including logging into a mail account and sending email, just like you would do from your own computer. You could even send email from a gmail account if you wanted.
http://swiftmailer.org/
I am using godaddy hosting . Just keep some fields blank and send mail it will work .
please see below code its working for me.
<?php
include("class.phpmailer.php");
function sendMail($address,$username,$body){
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
// $mail->SMTPAuth = true; // enable SMTP authentication
// $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
// $mail->Host = "smtp.gmail.com"; // sets as the SMTP server
// $mail->Port = 465; // set the SMTP port for the server
// $mail->Username = "xyz#gmail.com"; // username
// $mail->Password = "test121232"; // password
$mail->SetFrom('contact#example.co.in', 'Contact');
$mail->Subject = "Enquiry for tour and travels package";
$mail->MsgHTML($body);
$address = $address;
$mail->AddAddress($address, $username);
$mail->AddCC('contact#example.co.in');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
?>
just changed from email address, so you can send mail through this email id.
$mail->SetFrom('youremail#example.co.in', 'Contact');
I've had this issue on a couple of client accounts.
After MUCH playing around, I found that it didn't matter what email app or code you use.
I finally compared two accounts. One where I know email sends from PHP, and one where it doesn't. The difference I found was:
Working account had these 2 dns entries on the domain:
CNAME / mail / #
MX / # / mail.yourdomainname.com
And the MX Entry set within CPanel Zone Editor of:
Destination: yourdomainname.com
The account that was NOT working was the same, except it did not have the CNAME entry mentioned above. I added it, waited a few minutes and tested my code again and I finally started receiving the emails from my code!
This one worked for me.
I asked Godaddy and support they told me to use relays. So Instead of using mail() function, I used PHPMailer. Kindly check below the configuration for PHP Mailer.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 25;
$mail->setFrom('from#mail.com', 'From Mail');
$mail->addAddress('to#mail.com', 'To Mail');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body 123");
$mail->AltBody = 'HTML messaging not supported';
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message sent!";
}
Note: Here from#mail.com is my mail ID which is in cPanel mail accounts.

PHPMailer Contact form doesn't work on server, but does on localhost?

I have a PHPMailer Contact Form that sends data to a a GMail account. It does this successfully when the site is operated on localhost, but I get the following error when I've uploaded the webpage to a server and tried to use the contact form: Message could not be sent.Mailer Error: SMTP connect() failed.
I am uploading the files through Plesk to the server, though I doubt that's relevant. Here's the code:
<form action="currentFile.php" method="POST">
Full Name:<input required type="text" name="fullname"/>
<input type="submit"/>
</form>
<?php
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'mail#gmail.com';
$mail->Password = 'pass';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->addAddress('mail#gmail.com');
$mail->Subject = 'Contact Form';
$mail->Body = "Test";
$mail->AltBody = "Test";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
I believe changing $mail->isSMTP(); to $mail->isMAIL(); makes no difference. What could I do so that the form data is sent to the email when the site is online (on my server)?
Note: The gmail account and password used are meant to be "fake" in the code below. I do intend to to target a GMail account and I have put in the Google Mail address and password successfully, hence the script running successfully on localhost.
Thank you.
"#Fred-ii- Thanks this helped resolve my issue. Please post as an answer so I can give credit. – H3ll0 10 mins ago"
The action action="currentFile.php" belongs in <form>, not input and using either a GET/POST method.
You also need to use either method and assign/use an array for the input.
I.e.:
$var = $_POST['var']; // or $_GET depending on the preferred method.
There should also be a From: in the header, since that could send your mailout to spam or rejected altogether.
I.e.:
$mail->setFrom('from#example.com', 'First Last');
Reference links to troubleshoot:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
http://php.net/manual/en/function.error-reporting.php
Here is the github for PHPMailer:
https://github.com/PHPMailer/PHPMailer
If you don't have an SPF record (Sender Policy Framework), creating one would be beneficial.
https://en.wikipedia.org/wiki/Sender_Policy_Framework
http://www.openspf.org/

Setting up phpmailer on iis7

I recently moved from windows shared hosting to a VPS. I'm struggling to get phpmailer to work for a contact form on my website.
The code for my site the sets up the email to send is:
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->SMTPDebug = 1; // can vary the amount of debug info given on error
$mail->Username = "mail#mydomain.com"; // SMTP username
$mail->Password = "########"; // SMTP password
$mail->Port = 587;
This code worked on the old windows shared hosting. Also everything else is identical too with the site (the class.phpmailer.php file etc)
So I'm guessing it's something to do with my setup of iis or the server itself.
Connecting out works on port 587 according to my webhosts who checked that for me
I installed php using the Microsoft tool that does everything for you. the site is in php and is working, and it looks to my untrained eye like all is fine there.
I've checked that php_openssl.dll is enabled.
I've spent a long time reading around and fiddling with no luck. I'm really at a loss as what to look at next. Any ideas what it could be or what I should try?
thanks!
Phil.
EDIT:
The action on the php form is to go to contactprocessor.php.
That file contains this code:
<?
ob_start();
if(isset($_POST['btnSubmit']))
{
require("class.phpmailer.php");
$mail = new PHPMailer();
//Your SMTP servers details
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->SMTPDebug = 1; // can vary the amount of debug info given on error
$mail->Username = "mail#mydomain.com"; // SMTP username
$mail->Password = "########"; // SMTP password
$mail->Port = 587;
$redirect_url = "http://www.mydomain.com/contact/contact_success.php"; //Redirect URL after submit the form
$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "Website Contact Form";
$mail->AddAddress("mail#mydomain.com", "From Contact Form"); //Email address where you wish to receive/collect those emails.
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "From Contact Form";
$message = "FullName: ".htmlspecialchars($_POST['fullname'])." <br> <br>
\r\n <br>EmailAddress: ".htmlspecialchars($_POST['email'])." <br> <br>
\r\n <br>Phone Number: ".htmlspecialchars($_POST['mobile'])." <br> <br>
\r\n <br> Message: <br>".htmlspecialchars($_POST['message']);
$mail->Body = $message;
if(!$mail->Send())
{
echo "Sorry the message could not be sent. Please email mail#mydomain.com instead. Thanks<p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
header("Location: $redirect_url");
}
?>
Instead of actually sending the email, it just seems to print the above to screen of the user as if it's a webpage. it's as if the server thinks it's a html page and is just serving it.
You wrote:
Instead of actually sending the email, it just seems to print the above [code] to screen of the user as if it's a webpage. it's as if the server thinks it's a html page and is just serving it.
I think your problem is unrelated to phpMailer, or indeed email at all.
This is almost certain to be simply a small difference between the PHP configuration on your old and new servers.
Your PHP code is using the short-style PHP tags -- ie starting with <?.
Many PHP servers are configured not to allow this short-style tag, and only run PHP code that starts with the full <?php tag.
Given what you stated in the remark I quoted above, I suspect this is your problem, because what you describe is exactly the symptom I would expect from that.
You have two options:
Change your code to use the long style <?php tag.
Change your server config to allow the short <? tag.
I would recommend taking option (1) if possible, because the long-form tags are considered best practice (the short form is not recommended because it can have a potential clash with the <?xml marker at the start of most XML documents).
If you have a lot of short-form <? tags (and assuming you're allowed to do so), changing the server config may be worth considering, but if it's easy enough to fix the problem by switching to long tags, I'd say that would be better.
Hope that helps.
Thanks to Spudley for the answer. I had <? at the start (which is a shorthand that doesn't work on new php installations apparently). It should be <?php that's made it work. Thanks again.

php mail() from godaddy server

I'm using godaddy for hosting my site and using default godaddy mail service.
Now i want to sent email using php mail function to other email address from my 1 of my 15 email address of my godaddy's email accounts
How can i fix that from which email address email will be sent and how to place the username and password for the email address ?
Thanks
The PHP mail function uses the mailserver configured for that webhost. You can't change that. Since godaddy controls the mailserver they control what headers it sends. You could try inserting a custom From header but I doubt that will work. It will either get modified, flagged as spam, or rejected.
If you have 15 accounts at godaddy, perhaps it's time to look for a more serious hosting solution?
Instead of using the mail() function, which just calls the OS mail function (i.e. sendmail), try something like SwiftMail (free PHP mail library). It support many different ways of sending mail, including logging into a mail account and sending email, just like you would do from your own computer. You could even send email from a gmail account if you wanted.
http://swiftmailer.org/
I am using godaddy hosting . Just keep some fields blank and send mail it will work .
please see below code its working for me.
<?php
include("class.phpmailer.php");
function sendMail($address,$username,$body){
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
// $mail->SMTPAuth = true; // enable SMTP authentication
// $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
// $mail->Host = "smtp.gmail.com"; // sets as the SMTP server
// $mail->Port = 465; // set the SMTP port for the server
// $mail->Username = "xyz#gmail.com"; // username
// $mail->Password = "test121232"; // password
$mail->SetFrom('contact#example.co.in', 'Contact');
$mail->Subject = "Enquiry for tour and travels package";
$mail->MsgHTML($body);
$address = $address;
$mail->AddAddress($address, $username);
$mail->AddCC('contact#example.co.in');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
?>
just changed from email address, so you can send mail through this email id.
$mail->SetFrom('youremail#example.co.in', 'Contact');
I've had this issue on a couple of client accounts.
After MUCH playing around, I found that it didn't matter what email app or code you use.
I finally compared two accounts. One where I know email sends from PHP, and one where it doesn't. The difference I found was:
Working account had these 2 dns entries on the domain:
CNAME / mail / #
MX / # / mail.yourdomainname.com
And the MX Entry set within CPanel Zone Editor of:
Destination: yourdomainname.com
The account that was NOT working was the same, except it did not have the CNAME entry mentioned above. I added it, waited a few minutes and tested my code again and I finally started receiving the emails from my code!
This one worked for me.
I asked Godaddy and support they told me to use relays. So Instead of using mail() function, I used PHPMailer. Kindly check below the configuration for PHP Mailer.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 25;
$mail->setFrom('from#mail.com', 'From Mail');
$mail->addAddress('to#mail.com', 'To Mail');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body 123");
$mail->AltBody = 'HTML messaging not supported';
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message sent!";
}
Note: Here from#mail.com is my mail ID which is in cPanel mail accounts.

Categories