Error sending html email using Pear (PHP) - php

I am using pear to send SMTP mail with HTML format, everything was fine, but in the last report you make, the report goes wrong formatted and the reason is because the HTML adds an exclamation mark (!) In random parts and when it falls by means of a label or style moves everything. If someone can give me a hand.
function sendEmail($parameters) {
require_once "Mail.php";
print_r($parameters['emailBody']);
$from = "XXXXXXXXXX";
$to = $parameters['emailAddress'];
$subject = $parameters['reportName'];
$host = "XXXXXX";
$port = "XXXX";
$headers = array('From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-type' => 'text/html; charset=utf8');
$smtp = Mail::factory('smtp', array('host' => $host,
'port' => $port,
'auth' => false));
$mail = $smtp->send($to, $headers, $parameters['emailBody']);
}
<td>!</td>

Well after searching a bit, I found that HTML was not formatted, missing lines changes and apparently when this all in one line, is poorly formatted and interpreted otherwise.
Thanks for your time.

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.

PHP/PEAR Mail Not Sending as Text Message

I'm working on a script that will send text messages via email (i.e. ####txt.att.net) and PHP's simple mail() function was not working. I could send email messages just fine through that method, but the texts were not being delivered. I did more research and found that carriers often block messages without a sender and using PEAR with SMTP is a better solution.
However, the following code works to send emails but is still not delivering AT&T text messages:
<?php
require_once "Mail.php";
$from = "XXX <XXX>";
$to = "XXX <XXX#txt.att.net>";
$subject = "Test email using PHP SMTP\r\n\r\n";
$body = "This is a test email message";
$host = "XXX";
$port = "26";
$username = "XXX";
$password = "XXX";
$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>");
}
?>
Is it maybe an issue with headers not being formatted correctly, etc? Any ideas?
According to their example you do not need the new lines after the subject:
http://pear.php.net/manual/en/package.mail.mail.send.php
Check the AT&T response they might decline it if they have you blacklisted or you do not have a valid rDNS or other reasons.
They seem to experience a problem seeing the rDNS records of some IP's.
Use this it will tell you all the info you need.
http://wordpress.org/extend/plugins/xmail-the-right-way
Post the log of it here.

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/

PHP PEAR Mail Error

I'm getting an error with the following code when trying to send an email. It works on my local machine but not when I put it on my AWS LAMP server. I cannot debug anything because I'm getting an HTTP 500 error when I run the script. However, I know PEAR is installed.
Code:
require_once "Mail.php";
$from = "Email<Test#example.com>";
$to = "steve#exmaple.com";
$subject = "ERROR REPORT";
$body = "test message";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "test#gmail.com";
$password = "pass1";
$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("Error message sent!");
}
It appears to be bugging out at the send() command above. Any suggestions on how to better debug this?
Try the following two lines:
ini_set('display_errors','on');
error_reporting(E_ALL);
Placing those two early in the script bypasses the php.ini settings that would hide the errors otherwise. Hope that helps!
Also, if you can, place them in the PHP file that gets called and then include the file that uses the mail functions. That way, you avoid the code above not working due to a syntax error.
Have a look at the web server's error log, i.e. /var/log/apache2/error.log.

sending Emails using PEAR's Mail in PHP is working fine on Windows Dev System but not on Linux Server?

I am using following code to send email using mail.google
<?php
require_once "Mail.php";
$from = "someone#somedomain.com";
$to = "otherone#somedomain.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "mygmailaccount#gmail.com";
$password = "mygmailpassword";
$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>");
}
?>
This code works fine on Windows Development Machine but not on my Amazon Linux Server ?
Please tell me if any additional configuration is required.
Mail.php isn't the only file needed for sending mails via SMTP. You need the following files:
Mail.php
PEAR.php
PEAR5.php
Mail/smtp.php
Net/SMTP.php
Net/Socket.php
Mail/RFC822.php
At least these files were needed when I tried out your example on my own linux server.
I don't know how this Amazon web stuff is working but you probably need to look at some log-file or enable error messages in HTML output somehow or increase the warning level to find out what's really going wrong.
If you want to install the files manually you can download them from here:
http://pear.php.net/package/PEAR/download/
http://pear.php.net/package/Mail/download/
http://pear.php.net/package/Net_Socket/download/
http://pear.php.net/package/Net_SMTP/download/

Categories