How to explicitly disable TLS with PEAR Mail factory? - php

Using PHP, I'm attempting to route email through AuthSMTP (a hosted SMTP service). The problem is that the PEAR mail factory automatically tries to negotiation a TLS connection with the server. Rather than simply ignoring the attempt, AuthSMTP throws an error. I need a way to explicitly tell the Mailer class not to try to use TLS. Any suggestions?
$from = "Example <noreply#example.com>";
$to = $email;
$subject = "This is an email";
$body_text = "plain text here";
$body_html = "<h1>HTML here!</h1>";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$mime = new Mail_mime('rn');
$mime->setTXTBody($body_text);
$mime->setHTMLBody($body_html);
$body = $mime->get();
$hdrs = $mime->headers($headers);
$host = "mail.authsmtp.com";
$port = 26;
$username = "my_username";
$password = "whatever_password";
$mailer = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'port' => $port,
'username' => $username,
'password' => $password));
if (PEAR::isError($res)) {
throw new Exception($res->getMessage());
} else {
return true;
}
AuthSMTP is giving me the following error:
SMTP: Invalid response code received from server (code: 428, response: 4.0.0 Your account is using SSL - either disable it in your email client or enable it at http://control.authsmtp.com)

The easiest way is to change $tls=true to $tls=false in the definition of the function auth in PEAR\NET\SMTP.php

This can't be done with a current release of the PEAR Mail package - but is a requested feature. I've uploaded a patch so that this can be done. Hopefully a new release will be distributed soon.

Switched to using PHPMailer instead and had it working in 5 minutes.

Related

Sending SMTP Emails from PHP

I'm a bit stuck here. I have some websites hosted on TSOHosts. I use the php mail() function to send the occassional email, e.g. from a contact form.
The emails have stopped working, and nobody at the hosting provider seems to be capable of fixing it.
They say I should use SMTP emails. OK, I get that, they point me to this article on how to do it:
https://www.lifewire.com/send-email-from-php-script-using-smtp-authentication-and-ssl-1171197
So I write the script (below) and, it doesnt work:
require_once "Mail.php";
$from = "NoReply#mysite.org.uk";
$to = "me#myemailaddress.co.uk";
$subject = "Hi port 465";
$body = "Hello World";
$host = "ssl://mail3.gridhost.co.uk";
$port = "465";
$username = "username#mysite.org.uk;
$password = "Testing123";
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail))
{
echo "<p>".$mail->getMessage()."</p>";
}
else
{
echo"<p>Message successfully sent!</p>";
}
I also have a port 25, non-ssl script, that also doesnt work.
When I say doesnt work, its not throwing an error, just no email arrives (checked in spam).
The hosting company first asked me where the Mail.php is as referred to by the require_once "Mail.php" line
The article suggests that this should be installed on php4+ (Im using 5.6.37)
This is remarkably similar to this article:
smtp configuration for php mail
But I am stummped as to how to proceed.

Sending email to Office 365 using PEAR (PHP)

I am having some trouble figuring out why my emails are not being sent out to my Office 365 account. Before my companies migration to Office 365 we had an internal mail server and getting emails to send out was a piece of cake. However, now that we have moved to Office 365 it has become a real headache getting emails to send out. I thought that maybe I needed to set up an SMTP Relay and point to that server in my php code but it seems that is not the issue. Below is my code used to send out a test email:
$from = "example#example.com";
$to = "test_user#example.com";
$bcc = '';
$subject = "Hi!";
$body = "Hi,\n\nLooks like it worked.";
$host = 'smtp.office365.com';
$port = '587';
$username = 'example#example.com';
$password = '**********';
$headers = array(
'Port' => $port,
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => 'text/html; charset=UTF-8'
);
$recipients = $to.", ".$bcc;
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($recipients, $headers, $body);
echo "test";
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
Once I run this code I am presented with the following error:
authentication failure [SMTP: SMTP server does not support authentication (code: 250, response: SN1PR19CA0003.outlook.office365.com Hello [68.15.136.46] SIZE 157286400 PIPELINING DSN ENHANCEDSTATUSCODES XXXXXXXA 8BITMIME BINARYMIME XXXXXXXB)]
I have researched the heck out of this error and have had no luck in resolving my issue. I am wondering if it has something to do with the fact that the server I am generating the php code on is a development server and not on a live site. I am thinking that since this is not a live site I need to point it to a server that uses SMTP relay in order to get it out onto the internet, however, like I said I have had no luck when doing this.
Any assistance is greatly appreciated.
Thanks in advance.

Missing attachement in mail sent through Mime / SMTP Gmail Server (PHP, PEAR)

I am sending an Email from my server through SMTP Gmail using Pear's Mail Mime. However when I add an attachement it simply does not show up.
$smtpinfo["host"] = "ssl://smtp.gmail.com";
$smtpinfo["port"] = "465";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "xxx";
$smtpinfo["password"] = "xxx";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => utf8_decode($subject)
);
$mime = new Mail_mime();
$mime->setHTMLBody($html);
$mime->addAttachment("http://ww.url.of.a.file.that.exists.100percent.jpg", "image/jpeg");
$body = $mime->get(array('html_charset' => 'utf-8','charset' => 'utf-8'));
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', $smtpinfo);
$mail = $smtp->send($to, $headers, $body);
Everything works fine just the attachement is entirely missing..
I've been googling for hours.. I appreciate any hints..
My first thoughts would be to check the [boolean] response of the addAttachment method to see if it returns 'not found' or other type of indication(s)
$fileAttached = $mime->addAttachment("http://ww.url.of.a.file.that.exists.100percent.jpg", "image/jpeg");
echo ( !empty($fileAttached) ) ? "Attached successfully!" : "Uh, Houston?";
My initial thought is that it's expecting that 'file' to be 'loca' to your system and not accessed via http, etc. And, even if it DOES allow for HTTP access, you might also want to check your allow_url_fopen in the .ini file to insure it's set to 'enabled' {"On" if looking at your phpinfo() result.
Additional information on the 'file' -
http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php

SMTP email via PHP - through Send Grid

I am sending SMTP email from my PHP website, using SendGrid SMTP mail service. Everything works fine, but when I send large amounts (5,000), it takes a long time to load/send, then tries to restart over and over again, and doubles, triples,.... I just sent 30,000 emails by mistake! I need a way to see the mail que and delete them or stop the process when it does this.
How can I see the que of emails to be sent out? Or cancel them from being sent out?
Maybe through Pearl Mail?
Here is my code
require_once "Mail.php";
$from = $thom5;
$to = $allemailsever1.','.$thom5;
$subject = $_POST['subject1'];
$html = "
<html><body>
<p></p>
$thom
</body></html>
";
$host = "smtp.sendgrid.net";
$port = "587";
$username5 = "";
$password5 = "";
$mime = '1.0';
$content = 'text/html';
$charset="ISO-8859-1";
$three = 'Receipients <'.$thom5.'>';
$headers = array ('From' => $from,
'To' => $three,
'Subject' => $subject,
'Mime-version' => $mime,
'Content-Type' => $content,
'charset' => $charset);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username5,
'password' => $password5));
// Send notification //
$mail = $smtp->send($to, $headers, $html);
Sounds like your local script is having trouble managing the number of mails you are trying to send. You should implement a local queue, and since you are using PHP, a simple option is the Mail_Queue PEAR package
Use the Events API and check to see that each message is processed. http://docs.sendgrid.com/documentation/api/event-api/

How to send an email using php script?

<?php
require_once "Mail.php";
$from = "<niko#gmail.com>";
$to = "<niko#hotmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<niko#gmail.com>";
$password = "somepassworrd";
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host,'port' => $port,'auth' =>true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail))
echo("<p>" . $mail->getMessage() . "</p>");
else
echo("<p>Message successfully sent!</p>");
?>
When I try to execute these php script I get these error
FATAL ERROR Class Mail NOT found ON number line 18
I know the above question is possible duplicate of these
Send email using the GMail SMTP server from a PHP page
But its not working.My PHP version is 5.3.4 Xampp 1.7.4 version.
mail('caffeinated#example.com', 'My Subject', $message); \\ I tried these
But it shows a warning saying that missing headers.
How do I send an email Using the php script?
Can we send an email without using authentication in PHP ? Because vb.net uses server authentication but most of the code i found on google is without authentication for php. so I got a doubt
Finally please help me with these trying from an 2 hours or so!
The PHP mail() function is for sending mail via Sendmail. If you want to use some SMTP server, you can use Zend_Mail which makes this thing very easy:
http://framework.zend.com/manual/en/zend.mail.html
Using Zend_Mail you only need to write something like this:
$config = array('auth' => 'login',
'username' => 'myusername',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('sender#test.com', 'Some Sender');
$mail->addTo('recipient#test.com', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send($transport);
The above handles authentication for you and sends a mail.

Categories