I am currently using a function called send:
public function send(){
if ( !empty($this->request->data) ) {
$email = new CakeEmail('default');
$email->from(array($this->Auth->user('email') => $this->Auth->user('username')))
->to(array('helpdesk#example.com'))
->subject($this->request->data['Ticket']['subject'])
->send(array($this->request->data['Ticket']['issue']));
$this->Session->setFlash('Email Sent Successfully', 'default', array('class' => 'message update span9'));
$this->redirect(array('action' => 'index'));
}
to Send emails to our helpdesk and deposit them into their database. All is working EXCEPT the FROM always shows the username/email address from the configuration options. It is not masking the email with the users email.. I need this to happen so that we know who is having the support issue.
Does anyone have a suggestion here on what to do?
*Addition
This is an intranet application and thus we have an authenticated GENERIC USER using smtp settings. This is not spamming, we just want to know which user the Help Desk ticket came from when inserting to the DB.
Why are you using the Config default anyway?
If you use $email = new CakeEmail();, does the email sent references the Authenticated User email info.
Also, you should always use $email->sender('support#yourcompany.com', 'Your Company Support');. This ensures that if there is an issue the problem get redirected to you and not the user, your app is sending an email on his/her behalf.
I have that setup in my account and it works just fine. To Mark's point, it may not be legal (although, that does not seem to be your issue), but I know it is possible as I have currently a system setup that works with whatever email I want. I do not use any Config and also I do not use any SMTP
Related
I am currently building a support ticket platform in PHP language. (Laravel framework to be exact)
I would like to have the feature that customers can e-mail to a certain e-mail address and that the e-mail gets stored in our database as a ticket itself. ( Or at least calls a url or something with postdata )
How would I go about forwarding e-mails to a PHP url/script or something, can someone get me on track?
You could possibly use the ImapMailbox PHP library to connect to an email inbox, grab the message content, store the data in your database, then delete the email from the inbox.
Alternatively, you could use an external service like Postmark to receive inbound mail and send your server a webhook for processing in PHP.
Hope this helps.
You can send information to server and save message to the db before it will sends. You don't need to post it back to your server, here is some abstract code:
public function store(Request $request)
{
$message = $request->get('message');
$to = $request->get('to');
$user = Auth::user();
Ticket::create(['message' => $message, 'to' => $to->id, 'by' => $user->id]);
Mail::send('emails.ticket', $message, function($m) use ($to,$user){
$m->from('app#example.com', 'Your Application');
$m->to($to->email, $to->name)->subject('Email from user '. $user->name);
});
}
I am creating a simple contact us form using Laravel 5.1
public function sendMessage(){
$data = [
'name' => Input::get('name'),
'email' => Input::get('email'),
'subject' => Input::get('subject'),
'body' => Input::get('body')
];
Mail::send('emails.contact',$data, function($message) use($data){
$message->from($data['email'], $data['name']);
$message->to('smartrahat#gmail.com','Mohammed');
$message->subject($data['subject']);
});
Session::flash('success_message','Mail sent successfully!');
return redirect('contact');
}
Everything is working fine but the sender email address is not the one it get from the contact page. The email is sent from the address which I configure in .env
I want to have the email from the sender email address which he filled up contact form. Or, you can say I want to change the header information (only from, I can change other information).
Well Laravel will send the mail through the given smtp server. I guess the smtp server (e.g. google doing this) will not let you change your from address to another address then the account belongs to.
If you want to reply to this address directly in your email programm you can add $message->replyTo($data['email'], $data['name']);.
The $message variable inside the Mail::send() function is a SwiftMailer message instance. Therefore, you can work with headers just like the SwiftMailer documentation shows. Just use $message->getSwiftMessage() to get and manipulate the headers.
Also, you absolutely can change the From header, but if you change it to a different domain, you'll have to deal with phishing warnings in the client. You can resolve that by setting up DKIM and SPF records, and you will need to have access to the DNS settings for the domain to do that.
I'm using Google oAuth2 to authenticate my client then sending emails on their behalf using Zend (v1.12) SMTP, all using PHP. My question is how do I include the client's default email signature (as set in their Gmail settings) on the outgoing mail created using Zend?
I have full access to the client's Gmail so hoping there is a way to get their HTML signature and then add it to my html email body. Something like this:
...
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$obj=json_decode($_SESSION["access_token"],true);
$client_token=$obj['access_token'];
require_once 'Zend/Mail/Transport/Smtp.php';
require_once 'Zend/Mail.php';
$email = 'ClientJohn#abcco.com';//uses gmail business app
$token = $client_token;
$initClientRequestEncoded = base64_encode("user={$email}\1auth=Bearer {$token}\1\1");
$config = array('ssl' => 'ssl', 'port' => '465', 'auth' => 'oauth2', 'xoauth2_request' => $initClientRequestEncoded);
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$mail = new Zend_Mail();
// Not real code:
$signature=$_GET['client HTML signature'];
//
$mail->setBodyText('EMAIL_BODY'.$signature);
$mail->setBodyHtml('<b>EMAIL</b>_BODY'.$signature);
$mail->setFrom('ClientJohn#abcco.com', 'Client John');
$mail->addTo('michaelt#test.com', 'Michael F');
$mail->setSubject('EMAIL_SUBJECT');
$mail->send($transport);
} else {
$authUrl = $client->createAuthUrl();
}
...
I've reviewed the Gmail rest API (https://developers.google.com/gmail/api/) which doesn't say anything about signatures.
I've searched the web and reviewed numerous questions on Stack Overflow like: How to send an email in C# with gmail template/signature
but don't think this works as I'm not creating the signature, just want to get what the client already uses. This is promising, just not sure how to implement it into my code (as it's using codeigniter):
How can add email signature in codeigniter?
Most of the web searches are about the digital signature of the email. I'm looking for the actual HTML signature at the bottom of the email I create.
If there isn't a way to get it from Gmail I'm thinking I'll have to have each client send me an email, copy and paste their signature HTML string into a database, then will have to pull that HTML for every email based on the user...not ideal because if they change their signature they'll also have to tell me so I can update the DB.
The signature is a client specific setting that sadly cannot be retrieved, as said by borfast here: Sending email with signature using Gmail API
The signature is not added by the API because it is a setting on the
web client, not a global setting for the entire account. If you
configure your Gmail account on Thunderbird, Outlook or another email
client, Gmail will not add the signature either. You should think
about Gmail in two separate ways:
The web client interface, accessible at mail.google.com, which is just
an email client like any other; Your inbox, the place where messages
end up in, which is completely independent of the clients you use to
access it. In other words, this is an email client-dependent setting,
and the only thing the clients do is add a bit of text to the text you
write yourself, nothing else.
With this in mind, it would probably be a good idea for you to let your users create a separate signature in your application that you use when they send mail.
I have an application built in CodeIgniter. I needed some help with the following email related tasks. Please note all emails will require SSL.
1) Send email to congratulate and welcome the user to the site
2) Send an email to confirm a user account has been deleted should they choose to leave.
3) Send an email to alert the user for a request sent to them from another user.
4) Set up and send an email for "forgot username" and last but not not least
5) Send an email to reset password in case the user can't remember how to login.
Thanks for your help, appreciate it.
function signup(){
$data = array(
'sign_up_mail'=>'Welcome and thanks for joining...'
);
$htmlMessage = $this->parser->parse('user/email/signup_html', $data, true);
$txtMessage = $this->parser->parse('user/email/signup_txt', $data, true);
#send the message
$this->email->from('test#gmail.com', 'test app');
$this->email->to($this->input->post('email_address'));
$this->email->subject('Account Registration');
$this->email->message($htmlMessage);
$this->email->alt_message($txtMessage);
$this->email->send();
}
Would you use this listed below as the method for changing the message within the various emails?
data['message'] = "Hey there, you've got a follower request!";
$email = $this->load->view('email/template', $data, TRUE);
I presume this method works for simple things like user welcome and alerts etc. How would I go about connecting a process to resetting a username/password or confirming a deletion? How do you connect the email process with manipulating data in the db?
From your question, I think you are looking for some kind of authentication related tasks. If so, there is an authentication, library in codeigniter, that provides complete authentication system. Have a look, it it is useful to you. http://konyukhov.com/soft/tank_auth/
I'm using CakePHP to send automated emails to clients. It's been working great, but it seems some recipients aren't receiving our emails. So I decided to use the SMTP option for sending emails, and route emails through our email provider at Media Temple.
However, when trying to send email from a Media Temple account, I get the error "550- relay not permitted".
That sounds like the Media Temple server is just plain not allowing me to send mail through it.
That's odd because I've confirmed the username and password I'm using is correct and I can send mail via SMTP through it from my macmail client and iPhone mail client. I've also confirmed my cakephp email settings are correct, because I can send emails via SMTP with a gmail account with the exact same configuration in cakephp.
Any idea why I'm getting this error and how to resolve it?
Thanks
Here's the code that handles sending an email. I use this class just like the regular EmailComponent from within many different controllers.
class CanadafindsEmailerComponent extends EmailComponent
{
...
function send($content = null, $template = null, $layout = null) {
if(!in_array(TECHY_MONITOR_EMAIL,$this->bcc) && is_array($this->bcc))
$this->bcc[]=TECHY_MONITOR_EMAIL;
else if (!in_array(TECHY_MONITOR_EMAIL,$this->bcc) && !is_array($this->bcc))
$this->bcc=array(TECHY_MONITOR_EMAIL);
if(DEVSITE){//commented-out code are settings for smtp with gmail, which works fine
$this->delivery = 'smtp';
$this->smtpOptions = array(
'port'=>'465',//'465',
'timeout'=>'30',//'30',
'auth' => true,
'host' => 'ssl://mail.thenumber.biz',//'ssl://smtp.gmail.com',
'username'=>USERNAME,//'USERNAME#gmail.com',
'password'=>SMTP_PASSWORD//,
);
$this->to=$this->correctFormatOn($this->to);
$this->bcc=$this->correctFormatOn($this->bcc);
$this->cc=$this->correctFormatOn($this->cc);
$this->replyTo=$this->correctFormatOn($this->replyTo);
$this->from=$this->correctFormatOn($this->from);
}
return parent::send($content,$template,$layout);
}
function correctFormatOn(&$email){
if(is_array($email)){
$copiedEmail=array();
foreach($email as $singleEmail){
$copiedEmail[]=$this->correctFormatOnSingle($singleEmail);
}
$email=$copiedEmail;
}else{
$email=$this->correctFormatOnSingle($email);
}
return $email;
}
function correctFormatOnSingle(&$email){
$subEmails=explode(",",$email);
$fixedSubEmails=array();
foreach($subEmails as $subEmail){
$fixedSubEmails[]=preg_replace('/<?([^< ]+)#([^>,]+)[>,]?/i', '<$1#$2>', trim($subEmail));
}
$email=implode(",",$fixedSubEmails);
return $email;
}
}
The main problem I was having was that clients weren't receiving emails from our server, (and so I wanted to use an SMTP server to see if that would fix it, instead of the server's default email server).
But I managed to get those clients to receive emails from the server by making some other changes, thus removing the need to use SMTP and the Media Temple email server.
(As an FYI, I found that we were getting bouncebacks from client email servers stating Diagnostic-Code: smtp; 550 Access denied - Invalid HELO name (See RFC2821
4.1.1.1), but they were being sent directly back to the server, and going into the linux user account "www-data". (I read them in /var/mail/www-data, just using tail and vim). I found that postfix, which was handling the sending of emails, was marking the email sender's hostname (ie, "HELO name") as canadafinds3, the name I gave the server in Rackspace, not the domain name: canadafinds.com. So I changed that in /etc/postfix/main.cf, restarted postfix, et voila! No more bouncebacks from those particular clients, and everyone's happy again.)
I ended up writing my own PHP mail() script based on https://web.archive.org/web/20180401094709/http://www.dreamincode.net/forums/topic/36108-send-emails-using-php-smtp-direct/ in order to circumvent this error.