Pear Can't send email on Shared Hosting - php

I was working on a project for a client, it selects an email from a database and then sends an email to that address. Everything worked fine on my VPS server running CentOS 6, but when migrating to their shared hosting the program will no longer send the email. It will select the correct addresses, but no message will be sent, I've already installed Pear Mail and Mail_mime. Any thoughts?
This code connects to the server:
$headers['From'] = 'mail#openmailbox.org';
$headers['To'] = 'mail#openmailbox.org';
$headers['Subject'] = $asunto;
$params['host'] = 'smtp.openmailbox.org';
$params['port'] = '25';
$params['auth'] = 'PLAIN';
$params['username'] = 'mail#openmailbox.org';
$params['password'] = 'password';
This code selects the recipients:
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$addresses[] = $row['email'];
}
$recipients = implode(", ", $addresses);
Hope you can help me!

Here, this is my email sending code
$mail =& Mail::factory('smtp', $params);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail->send($recipients, $headers, $body);

Well, I solved it. I replaced pear mail with the default mail function.

Related

mail.php script not working for subscribe and contact page [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
My web developer made this script to send notifications to people subscribing to my mailing list and the people who contact me, through the form on my website
The problem is, the recipients are not able to receive the emails, and I am not able to receive the notification on my mail id about a new subscriber or a contact
Sender id - notifications#llaveshagarwal.com
Moreover, the same script works on his server (which we used for testing) but doesn't work on my server
Is there a problem with my SMTP server settings ?
Also, I am using Google Apps for Gmail
Here is his script
What should I do ?
<?php
if($_POST['type'] == "subscribe") {
/*$to = "notifications#llaveshagarwal.com";
$subject = "New Email Subscriber";
$txt = "Name: ".$_POST['name']."\r\nFrom: ".$_POST['from'];
$headers = "From: ".$_POST['from'];
mail($to,$subject,$txt,$headers);
$to = $_POST['from'];
$subject = "Thank you for subscribing with us.";
$txt = "Hey ".$_POST['name']." ,\r\nGreetings from LLavesh Agarwal Textile Agency\r\nThank you for subscribing with us for Exclusive and Latest Catalogs and product launches.\r\nWe will update you soon.\r\n\r\nRegards,\r\nTeam LLavesh Agarwal\r\n\r\n*This is an automated Email. Please do not reply to this Email id. If you wish to talk to us, kindly Email us at hello#llaveshagarwal.com";
$headers = "From: notifications#llaveshagarwal.com";
mail($to,$subject,$txt,$headers);*/
$link = mysql_connect('localhost', 'llavesha_admin', 'Admin#1234');
$db= mysql_select_db('llavesha_contact_system', $link);
$insert='insert into subscribe (name,email) values ("'.$_POST["name"].'","'.$_POST["from"].'")';
if(mysql_query($insert)) {
echo "success";
} else {
echo "fail";
}
}
elseif($_POST['type'] == "contact") {
$to = "notifications#llaveshagarwal.com";
$subject = "New Contact";
$txt = "Name: ".$_POST['name']."\r\nContact: ".$_POST['mobile']."\r\nCategory: ".$_POST['bussiness_type']."\r\nDescription: ".$_POST['project_detail'];
$headers = "From: ".$_POST['from'];
mail($to,$subject,$txt,$headers);
$to = $_POST['from'];
$subject = "Thank you for contacting us.";
$txt = "Hey ".$_POST['name']." ,\r\nGreetings from LLavesh Agarwal Textile Agency\r\nThank you for contacting us.\r\nWe will update you soon !\r\n\r\nRegards,\r\nTeam LLavesh Agarwal\r\n\r\n*This is an automated Email. Please do not reply to this Email id. If you wish to talk to us, kindly Email us at hello#llaveshagarwal.com";
$headers = "From: notifications#llaveshagarwal.com";
mail($to,$subject,$txt,$headers);
echo "success";
}
?>
Are you working on windows (wamp)? Have you enabling php sendmail on php.ini? read: http://us3.php.net/manual/en/function.mail.php
or you can read: php mail() function on localhost
If you want to make it simpler, use phpmailer instead: https://github.com/PHPMailer/PHPMailer
How to use it by #pooria: How to configure PHP to send e-mail?
require('./PHPMailer/class.phpmailer.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';
$body = 'This is the message';
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Username = 'me.sender#gmail.com';
$mail->Password = '123!##';
$mail->SetFrom('me.sender#gmail.com', $name);
$mail->AddReplyTo('no-reply#mycomp.com','no-reply');
$mail->Subject = 'subject';
$mail->MsgHTML($body);
$mail->AddAddress('abc1#gmail.com', 'title1');
$mail->AddAddress('abc2#gmail.com', 'title2'); /* ... */
$mail->AddAttachment($fileName);
$mail->send();

How to use smtp send mail and bcc in PHP

I have a PHP script and I want to send messages via the bcc attribute. But this PHP script sends the message but does not send as bcc. The bcc addresses appear in the email message.
// Construct the email
$recipient = 'me#mydomain.com';
$headers = array();
$headers['From'] = 'ME <me#mydomain.com>';
$headers['Subject'] = $subject;
$headers['Reply-To'] = 'no-reply#mydomain.com';
$headers['Bcc'] = 'abc#anotherdomain.com, xyz#thatdomain.com';
$headers['Return-Path'] = 'me#mydomain.com';
//$params['sendmail_args'] = '-fme#mydomain.com'; // this does not work
$body = 'message body';
// Define SMTP Parameters
$params = array();
$params['host'] = 'mail.mydomain.com';
$params['port'] = '25';
$params['auth'] = 'LOGIN';
$params['username'] = 'me#mydomain.com'; // this needs to be a legitimate mail account on the server and not an alias
$params['password'] = 'abcdef';
// Create the mail object using the Mail::factory method
include_once('Mail.php');
$mail_object =& Mail::factory('smtp', $params);
// Send the message
$mail_object->send($recipient, $headers, $body);
Here's something that I found: "If the Cc or Bcc lines appear in the message body, make sure you're separating header lines with a new line (\n) rather than a carriage return-new line (\r\n). That should come at the very end of the headers."
You might also want to try moving that header before or after others to see if it fixes things.
An even better solution would be to switch to phpMailer, which is supposedly a much, much better solution for sending mail through php.

sending emails with empty body

Is there any reason why phpmailer will send emails with empty body on a remote server but works fine on a local server?
The code is the same
$res = $db->run("SELECT * FROM email WHERE code = 'welcome'");
$m = $res[0];
$body = nl2br($m['content']);
$body = str_replace("[EMAIL]", $ld['email'], $body);
$body = str_replace("[PASSWORD]", $ld['password'], $body);
$mail = new PHPMailer();
$mail->AddReplyTo($m['from_address'], $m['from_name']);
$mail->AddAddress($ld['email'], "");
$mail->SetFrom($m['from_address'], $m['from_name']);
$mail->Subject = $m['subject'];
$mail->AltBody = strip_tags($body);
$mail->MsgHTML($body);
if ($mail->Send() === false)
{
p($mail->ErrorInfo);
}
unset($mail);
If anybody finds this and has no clue just like me, an update to phpmailer 5.2.6 will fix this.

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

Mail not sent in php pear mail package

I am trying to use PEAR Mail to send from my gmail address using below code,
<?php
include("Mail.php");
echo "This test mail for authentication";
try{
$from_name = "Test";
$to_name = "from name";
$subject = "hai";
$mailmsg = "Happy morning";
$From = "From: ".$from_name." <frommail#gmail.com>";
$To = "To: ".$to_name." <tomail#gmail.com>";
$recipients = "tomail#gmail.com";
$headers["From"] = $From;
$headers["To"] = $To;
$headers["Subject"] = $subject;
$headers["Reply-To"] = "gunarsekar#gmail.com";
$headers["Content-Type"] = "text/plain";
$smtpinfo["host"] = "smtp.gmail.com";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "mymail#gmail.com";
$smtpinfo["password"] = "mypassword";
//$smtpinfo["debug"]=True;
$mail_object =& Mail::factory("smtp", $smtpinfo);
$mail_object->send($recipients, $headers, $mailmsg);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}catch(Exception $e){
echo 'Caught exception: ', $e->getMessage(), "\n";
}
echo "<br>Fin";
?>
this code not return any error or warning , it simply shows "Message successfully sent!"
but, mail not receiver to mail the address.
can any one please tell what problem in mycode or what actually happening.,
The first thing I see is that you have a mistake: Your check checks against an variable called $mail, but everything else refers to $mail_object. If that's in your actual code, then I'm guessing that might be part of it.
Some basic checks:
Did you check to make sure that you have POP or IMAP enabled in Gmail?
Have you set up this account with the same username and password on a normal machine, to ensure you can send and receive email outside of PHP?
Verify that you can even talk to the GMail server (that it isn't blocked for some reason) by pinging smtp.gmail.com or using telnet to open a connection to port 25: telnet smtp.gmail.com 25
Read over the Gmail help for sending email.
Beyond that, it looks like GMail requires TLS or SSL, which means you have to use port 587 or port 465. I don't know if that package can handle encrypted connections, though. (Even on port 25, GMail requires SSL encryption.) That may preclude this from working at all.

Categories