I am currently working on a project where I am accessing an e-mail account using PHP's imap_open(). I know that I can send an e-mail with PHP using the mail() function.
However, I was wondering if, after I send an e-mail, I could place that e-mail in the email account's sent folder using any of PHP's imap functions.
Any help would be greatly appreciated.
This is more to email account setting to save the email sent to sent account folder.
You may try with external mail that already configured to save email sent to sent folder e.g Gmail http://www.vulgarisoip.com/files/phpgmailer.zip
example :
require_once('/phpgmailer/class.phpgmailer.php');
$mail = new PHPGMailer();
$mail->Username = 'user#domain.com';
$mail->Password = 'password';
$mail->From = 'user#domain.com';
$mail->FromName = 'User Name';
$mail->Subject = 'Subject';
$mail->AddAddress('myfriend#domain.com');
$mail->Body = 'Hey buddy, here\'s an email!';
$mail->Send();
Related
So as stated in the title I wanna created a function different from mail to send mail(confusing ik)
So using mail () it sends the email from my server regardless of the headers I put so I need to create a function to send the actual email from a set email
Let's say I have an email
flameforgedinc#gmail.com
Lets say I have a bunch of emails in a mailing list
Now I have some code that's gonna use this function to email each one
So this code use's cMail ($to, $sub, $msg, $from);
And the email will appear to the user
From: flameforgedinc#gmail.com
And I actually want it to come from my email
If I use mail then it comes from my server and displays altervista00000 and I don't want the plus my server limits the mail() function to activation emails and I need to be able to send newsletters
Any ideas or workarounds??
My name is Pavel Tashev. I will try to help ;)
The easiest and more correct way from technical point of view is to use your own Mail server which hosts your email account and sends your emails. The purpose of PHP in that cases will be to tell the mail server to send email X to a list of emails Y, from an email account Z.
This will solve all your problems:
max allowed emails per hour;
sender name;
The good news is that you already have a Gmail account which is hosted by Google and you don't need to build your own mail server. You can use Google's mail server. Also, for the email sending I would advice you to use PHPMailer (url: https://github.com/PHPMailer/PHPMailer).
Here is how we can do all of this. Follow these steps:
Integrate PHPMailer in your project. If you use composer, that will be a straightforward process. If you don't, simply download the code and include this file PHPMailerAutoload.php in your project. Just follow the instructions on Github. It is really easy.
So, when you are ready with the installation of PHPMailer you must tell it to connect to your mail server. For Gmail and your email account this would look like this:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'flameforgedinc#gmail.com';
$mail->Password = 'PUT-YOUR-PASSWORD-HERE';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('flameforgedinc#gmail.com', 'YOU CAN PUT YOUR NAMES HERE IF YOU WANT');
The final step is to set up the recipient and the content of the email:
$mail->addAddress('some.user#example.net', 'Joe User');
$mail->addAddress('seconrd.user#example.com', 'The name is optional');
$mail->addReplyTo('flameforgedinc#gmail.com', 'YOU CAN PUT YOUR NAMES HERE IF YOU WANT');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
now you will have to send the email:
!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
I hope that will help.
I'm trying to set up a web site on a (shared) web hosting account. And I'm facing an issue with the mail() method. The site has a contact form where a user can submit their feedback:
Name: _____________
Email: ____________
Message: __________
So I was using the mail() method as such to send it as an email to my own account:
if(mail("mysitecustomerfeedback#hotmail.com",
"Customer message",
$message,
"From: $name <$email>\r\n".
"Reply-To: $name <$email>\r\n".
"X-Mailer: PHP/".phpversion()) === true)
{
$messageWasSent = true;
}
So when I try it, the email is dispatched, but there are several issues with it.
For instance, for my test I provided my actual email, say, johndoe#hotmail.com but when the email is received in my mysitecustomerfeedback#hotmail.com Hotmail account, the from email field is filled out with the default email on the shared hosting server, or something like web-user234#server875.web-hosting.com and not johndoe#hotmail.com as I would expect it to be.
Also the email was automatically placed into Junk by Hotmail, even though it contained no attachments, images, or anything. It was a plain text message.
Here's a screenshot:
So I understand that this shared hosting company doesn't want me to send spam using mail() method, but how else can I send these emails off my web site? Is there a replacement method for mail()?
You can use PHPMailer.
Example:
$mail = new PHPMailer;
$mail->isSMTP();
// You can use the SMTP host/auth details
// supplied by your personal email provider.
$mail->SMTPAuth = true;
$mail->Host = 'smtp.example.com';
$mail->Username = 'myUsername';
$mail->Password = 'myPassword';
$mail->setFrom('my#example.com');
$mail->addAddress('to#example.com');
$mail->Subject = 'A subject.';
$mail->Body = 'A message.';
$mail->send();
Since you authenticate with hotmail/gmail or whichever email server you use, the recipient will receive the email just as if you sent it using your favourite email client (this is a PHP email client).
I am able to send emails to individual email ids using PHPMailer.
But, I am not able to send email to group email using PHPMailer. I am not talking about sending multiple emails using loop.
Suppose, I have an email group#example.com and this is a group email. That means, if we send email to this, it will be received by all the people added to this email group.
I tried sending email to group email but no one received the email. I am using same domain sender email id. For ex: noreply#example.com
My code looks like below
$mail = new PHPMailer();
$mail->From = 'noreply#example.com';
$mail->FromName = 'FromName';
$mail->Subject = 'Subject';
$mail->Body = 'Body';
$mail->isHTML(true);
$mail->AddAttachment($file);
$mail->AddAddress($groupEmail);
if(!$mail->send()){
//error msg
}
I am using gmail SMTP to send the mail with the help of phpmailer library. It is sending mails fine but it is not sending from the mail address that I am setting in SetFrom address. Here is my code:
<?php
require 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "myusername#gmail.com";
$mail->Password = "gmail_password";
$mail->From = 'donotreply#mydomain.com';
$mail->FromName = 'Admin';
$mail->AddAddress('Toreceiver#test.com', 'Receiver'); // Add a recipient
$mail->IsHTML(true);
$mail->Subject = 'Here is the Subject';
$mail->WordWrap = 50;
$mail->Body = "This is in <b>Blod Text</b>";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>
It is sending mail from myusername#gmail.com but I want it to send with 'donotreply#mydomain.com' as set in $mail->From. Any help will be highly appreciated.
Yes, this is a Google Mail restriction. The "From" email address must match or is automatically set that way by Google SMTP.
My solution was to add
$mail->AddReplyTo($FromEmail, $FromName);
This way at least if you reply to the message it will be delivered as described
There is another way to set from address in phpmailer and it is better supported. I found that server where i used phpmailer didn't pass email to another server from the same host. But then i change the way how i set the from address and it solve the problem.
Use:
$mail->SetFrom('donotreply#mydomain.com', 'Admin');
Instead of $mail->From and $mail->FromName.
if you want to use different email address as sentFrom, then you can set your email from gmail settings:
settings > Accounts and import > Send mail as:
set another email which you want to use as from:
if you are using zoho then you can follow:
settings > Mail tab > Send mail as > add from address
then verify that email.
For GSuite users...
What Jyohul said, is the correct way of doing it. You can add an alias in Google Admin Console, under "Users". Click on the user's name, and then click on "user information". In there you can add Aliases. Once the aliases are added, you can then do what Jyohul said, which I added a needed step...:
if you want to use different email address as sentFrom, then you can set your email from gmail settings:
Go to your Gmail, then click the gear on the top right, then:
settings > Accounts > Send mail as: then click "Add another email address".
Upgrade to the latest version of PHPMailler. You should also make sure that you turn on debuging in oder to view erro messages.
$mail->SMTPDebug = 2;
You will the identify the error. Also make sure your SMTP Server credentials are correct. Like host, username and password.
Mine worked correctly
I'm trying to send a mail with PHPmailer and gmail. But when I send a mail its from my gmail account instead of no-reply. How do I set no-reply as from?
Code I have:
$mail = new PHPMailer();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "myAccount#web.com";
$mail->Password = "password";
$mail->From = "no-reply#web.com";
$mail->AddAddress($to);
$mail->AddReplyTo("no-reply#web.com","no-reply");
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->WordWrap = 150;
$mail->send();
The mail I get receives (headers):
Return-Path: <myAccount#web.com>
Which should be no-reply#web.com
Thanks in advance
There are two options I would recommend trying:
Log in to the Google Apps mail account for myaccount#web.com, go to Settings, then Accounts, then Send mail as, and ensure that no-reply#web.com has been validated. I haven't tested this, but this should allow to send mail from no-reply#web.com, rather than from no-reply#web.com on behalf of myaccount#web.com.
Actually create a user on Google Apps with the username no-reply#web.com, and send email through that account. If myaccount#web.com needs a copy, you could always BCC the address and setup a filter on no-reply#web.com to forward any failures to myaccount#web.com.
You can't do it. Just imagine sending mail prompting to reply with your bank account credentials from an address validation#yourbank.com.
To have no-reply address you must have an access to the mail server in #your.domain (not gmail) and create such account there, then send emails using this account.