Using PHPMailer when popen is disabled - phpmailer

Is it possible to use PHPMailer to send an email from a php script on shared hosting where popen() is disabled? I am trying to send an email using the code below but get the error message "popen has been disabled for security reasons". On checking with my host provider it has indeed been disabled and cannot be enabled on shared hosting. Does this make PHPMailer unusable for me?
$mail = new PHPMailer();
$mail->SetFrom('info#byetunes.com', 'Byetunes');
$mail->AddReplyTo($param['sender_email'], $param['sender_name']);
$mail->AddAddress($receiverEmails[0]);
$mail->isHTML(true);
$mail->isSendmail(true);
$mail->Subject = $param['subject'];
$mail->Body = $message_body;
$sendingStatus = $mail->send();

You only need popen because you're using isSendmail - why are you doing that?
If you use isMail (the default, most likely to work on shared hosting) or isSMTP, you don't need popen.

Related

Changing Email address through phpmailer

Can I change <help.akunatch#gmail.com> through phpmailer?
Yes. You can set the from address using the From property (and the name via the FromName property), or using the setFrom method to do both at once:
$mail->From = 'myotheraddress#example.com';
$mail->FromName = 'Akunatech support';
or:
$mail->setFrom('myotheraddress#example.com', 'Akunatech support');
That said, I can see you're sending through gmail, which does not allow you to use arbitrary from addresses (it will revert to your account address if you try), but you can configure aliases in gmail settings.

PHPMailer 5.2.x - Centrally set PHPMailer SMTPAuth credentials

We inherited an older PHP application. It is an online shop application coded in weird style. Each mail procedure has been coded into the responsive PHP file on the fly. There are lots of files which can hold code to send out mails.
Problem is, the new webserver uses a mailserver that demands SMTPAuth to accept mails for sending. The code doesn't provide any SMTPAuth credentials because the former hosting didn't use it.
The scripts are using PHPMailer.
My question is if there is any way to centrally set SMTPAuth credentials (host, username, password) which will be used by PHPMailer automatically always while sending out mails?
I do not want to touch the foreign code and alter each script so it uses SMTPAuth like:
$mail->IsSMTP = true;
$mail->Host = "blah";
$mail->Username = "xxx";
and so on.
I hope my intention is clear. Please ask if there are questions.
Don't edit the original files - otherwise when you update PHPMailer, your code will break - subclass instead, like this:
class myMailer extends PHPMailer {
public function __construct($debug = false) {
parent::__construct($debug);
$this->Username = 'username';
$this->Password = 'password';
$this->isSMTP();
$this->SMTPAuth = true;
}
}
then use it whenever you want an instance, so instead of saying
$mail = new PHPMailer;
say
$mail = new myMailer;
This approach is how you should always use libraries; it's not specific to PHPMailer.
I've solved it.
Just set the values in class.phpmailer.php of the public vars:
$Mailer // to "smtp"
$Host // to the mail host
$SMTPAuth // to true
$Username // to the mail accounts username
$Password // to the mail accounts password
That's all.

How can I set google mail to not put php mail in spam folder?

I am creating a site for me only that will run from my server. I would like it to send me emails using php which is setup, but the emails go into my spam folder in gmail. How can I change this in gmail, not php, to send these emails to my inbox? I have tried using mail() and phpmailer().
Here is the Php code that I have.
$mail = new PHPMailer();
$body = "email from server - testing.";
$from = "email#mysite.com";
$email = "myemail#gmail.com";
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPDebug = 2;
$mail->SetFrom($from, "mysite.com");
$mail->AddReplyTo($from, "mysite.com");
$mail->Subject = "emails";
$mail->MsgHTML($body);
$address = $email;
$mail->AddAddress($address, "me");
// $mail->Send();
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I cannot see anything wrong with your code, since you seem to be setting the From correctly. I would however suggest that you check the actual headers received by GMail (Show Original under message options on the email/message) and check that the From header is correct. An incorrect sender is a common cause of issues like this.
As sarnold says above there is a degree of guess work involved, but I suggest you look at one or more of the following:
Check/Setup SPF or DKIM for your domain
Check/Setup a reverse dns record for the IP address used to send the emails
Check if the IP address you are sending from is on any blacklists (contact your ISP if it is). MXToolBox BlackList Checker may be useful for checking multiple blacklists

Web2py - Using a Gmail address

I am beginner with web2py. I have just created a new project.
I want to use a gmail address, let's say g#gmail.com. What do I need to modify ?
mail.settings.server = 'logging' or 'smtp.gmail.com:587' # your SMTP server
mail.settings.sender = 'g#gmail.com' # your email
mail.settings.login = 'g#gmail.com:mypassword' # your credentials or None
Is this OK ?
What is the purpose of 'logging' ?
Should be
mail.settings.server = 'smtp.gmail.com:587'
Setting mail.settings.server = 'logging' has the effects of logging to console requests for sending emails but does not send the emails. It is useful for debugging email problems.

'Microsoft.SharePoint.MailMessage' is inaccessible due to its protection level

'Microsoft.SharePoint.MailMessage' is inaccessible due to its protection level
On this code:
MailMessage mail = new MailMessage();
mail.From = "myemail#xxxxx.edu";
mail.To = "myemail#xxxx.edu";
mail.Subject = "Testing Code";
mail.BodyText = what;
mail.Priority = MailPriority.High;
Smtp.Send(mail, "smtp.xxxxx.edu");
How can remidy this? changes to web.config? Any way to circumvent in code?
This error is saying that MailMessage does not have public constructor. Most likely, it is for internal SharePoint use only.
Actually, in most cases in SharePoint you need to use SPUtility.SendEmail method to send mail with SharePoint. It is very simple:
SPUtility.SendEmail(SPContext.Current.Web, false, false, "myemail#xxxxx.edu", "Testing Code", what);
See MSDN for details on this method:
http://msdn.microsoft.com/en-us/library/ms411989.aspx
If you need to send email under ordinary user accounts, you should use SPSecurity.RunWithElevatedPrivilegies method to provide elevated privilegies.
Only disadvantage is that SPUtility does not support attachments. If you need attach some files to your letter, please use System.Net.Mail.
I know a good post from Edwin Vriethoff, which provide detailed information about sending email with attachments, with default SharePoint SMTP settings (they are configured through Central Administration):
http://edwin.vriethoff.net/2007/10/02/how-to-send-an-e-mail-with-attachment-from-sharepoint/

Resources