Is there no ways to retrieve bounce message from mailbox like yahoo, gmail? - email

I use Zend mail to read in the mail box ,
and i would like to filter out the bounce message from all other mail. So, below is the code i use to retrieve the header
The problem are:
1) Is gmail, yahoo etc.. not sending the actual bounce message? I can not detect any failed-receipent, diagnostic code from header
2) If not, then if i would like to notify the user what are the fail message, all i can do is only check whether there is a 'fail' or some similar phase in header, and using mail reg- exp to detect the fail recipient mail in the content?
Thank you for helping.
<?
set_include_path($_SERVER['DOCUMENT_ROOT'].'/fyp/plugin');
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
Zend_Loader::loadClass('Zend_Mail');
$mail = new Zend_Mail_Storage_Imap(array('host' => 'imap.gmail.com',
'user' => 'fff#gmail.com',
'password' => 'ffff',
'ssl' => 'SSL',
'port' => 993
));
$substring="Return-Path: <>";
foreach ($mail as $message) {
foreach ($message->getHeaders() as $name => $value) {
if (is_string($value)) {
echo "$name: $value\n";
echo "<br>";
}
}
}
?>

Related

Laravel-why admin receives every email message?

I am working on a web application with multiple users, and I have some issue with sending emails.
Sending is working fine, no problems, but the issue is that every mail interaction between visitors and users is sent to admin email address stated in env file. I am using gmail for sending, Laravel 8.
For example, visitor A has sent a message to user B. User B received mail correctly, but also admin received message.
Thanks for help.
Here is my EmailsController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
class EmailsController extends Controller
{
public function send(Request $request)
{
function sentence_case($string) {
$sentences = explode(" ",$string);
$sentences = array_reverse($sentences);
$new_string = '';
foreach ($sentences as $key => $sentence) {
$new_string = ucfirst(mb_strtolower(trim($sentence)))." ".$new_string;
}
return $new_string;
}
$this->validate($request, [
'ime' => 'required', //visitor name
'email' => 'required', // visitor email address
'poruka' => 'required' //visitor message
]);
$ime = $request->get('ime');
$ime = sentence_case($ime);
$email = $request->get('email');
$poruka = $request->get('poruka');
Mail::send('emails.message', [
'name' => $ime,
'email' => $email,
'comment' => $poruka ],
function ($m) use ($email) {
$m->from($email);
$m->to('usersemail#yahoo.com', 'MyApp')
->subject('Website Contact Form');
});
/* usersemail#yahoo.com is registered user email address different from aplication admin/owner email addres stated in env file, but admin receives this message */
if (Mail::failures()) {
return response()->Fail('Sorry! Please try again latter');
}else{
return back()->with('success', 'Thanks for contacting me, I will get back to you soon!');
}
}
}

How to send email with dynamic sender in laravel?

I am creating a simple contact us from in Laravel.
I set up .env with my Gmail account. I can send email from Laravel with my email address, no problem with this.
But, I want to send email from sender address who is sending the message form contact us form.
Here is my code in controller:
public function sendMessage(Request $request)
{
$this->validate($request,[
'email'=>'required|email',
'subject'=>'required',
'body'=>'required|max:150'
]);
$body = $request['body'];
Mail::send('emails.support',['body' => $body], function($message){
$email = Input::get('email');
$subject = Input::get('subject');
$message->sender($email);
$message->to('smartrahat#gmail.com','Mohammed');
$message->subject($subject);
});
return redirect('contactUs');
}
Though, I am getting email address form contact us form, the email always sent form my email account which I configured in .env
I would have done some things different. I guess $body is the email-text? You should put this in a array and add it as a parameter in Mail::send (or directly put $request->all() as a parameter.
Also, inside of the closure of Mail, i don`t thinks its very nice to put logic there (like $email=Input::get). It does not look right if you ask me.
Didn`t test this code, but this should work:
public function sendMessage(Request $request)
{
$this->validate($request,[
'email' => 'required|email',
'subject' => 'required',
'body' => 'required|max:150'
]);
$data = [
'email' => $request->input('email'),
'subject' => $request->input('subject'),
'body' => $request->input('body')
];
Mail::send('emails.support', $data, function($message) use ($data)
{
$message->from($data['email']);
$message->to('smartrahat#gmail.com','Mohammed');
$message->subject($data['subject']);
});
return redirect('contactUs');
}
Because you add $data as as 'use', you can access this data inside the closure. The $data send as a parameter, can be used in the email blade. In this example, you can access the data like this: $email , $subject , $data, in blade these will output the values.
But you can also do it like this:
Mail::send('emails.support', $request->all(), function($message) use ($data)
public function reset_password(Request $request)
{
$user=User::whereEmail($request->email)->first();
if(count($user) == 1)
{
$data = array('name'=>"Virat Gandhi");
$subject=$request->email;
mail::send(['emails'=>'reset_set'],$data,
function($message)use($subject)
{
$message->from('your#gmail.com','kumar');
$message->to($subject);
$message->subject($subject);
});
echo "Basic Email Sent. Check your inbox.";
}
}
foreach ($emails as $value1)
{
$to[]=implode(',',$value1['0']);
}
$subject=$request->input('sub');
$mailsend=Mail::send('email.subscribe',$mail_content,
function($message)use($to,$subject)
{
$message->from('ganarone#ganar.io','Ganar');
$message->to($to);
$message->subject($subject);
});

Sent email appears in recipient's spam folder in cakePHP using gmail account?

I am Using cakephp for one of my project. for sending email I am using cakeEmail. For that I created one gmail account for sending emails(i.e. used in code for send mail from that account).Mail sending works but sent mail appears recipient's spam folder.
Also in gmail account that mail dosen't appear sent mail folder.
code is as bellow :
In /app/Config/email.php file is :
class EmailConfig {
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'username#gmail.com',
'password' => 'password',
'transport' => 'Smtp'
);
}
and code in my controller file for password recovery is :
public function _sendemail($user_data,$temporary_password){
$email = new CakeEmail();
$email->config('gmail');
$email->template('welcome', 'password_recovery_email'); //template
$email->emailFormat('html');
$email->viewVars(array(
'temporary_password'=>$temporary_password,
'user_data'=>$user_data
));
$email->from(array('username#gmail.com' => 'Password Recovery'));
$email->to($user_data['User']['email_address']);
$email->subject('password recovery email');
$result=$email->send();
}
Please tell me what should I do to get all sent emails to appears in inbox rather than spam folder.
Thanks
A lot of reasons can make your email be considered a SPAM.
Maybe Gmail can't check the sender (smtp source/your developing machine) as a trusted sender. Have you tried uploading your php script to another server (production) then sending it from there?
Have you tried changing the message content/subject to something different from "Recover your password"?
Have you tried sending the same message to another recipient?
Gmail uses a lot of rules to check whether an email is a spam or not, check out this link: https://webapps.stackexchange.com/questions/5773/how-gmail-and-other-mail-services-detects-a-mail-as-a-spam
Try using this code rather than cakephp's methods:
$subject = "Your Email Subject";
$to = "Recipient's Email Address";
$from = "Your Email Address";
$additional_headers = "From: $from\r\n";
$additional_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$additional_headers .= "MIME-Version: 1.0\r\n";
$additional_headers .= "Return-Path: $from\r\n";
$additional_headers .= "X-Priority: 3\r\n";
$additional_headers .= "X-Mailer: PHP\r\n";
$message = "Your Email Body";
mail($to, $subject, $message, $additional_headers, "-f $from")

CakePHP 2.1.0: Capture E-mail Output

I'm building a CakePHP website that sends an e-mail like this:
$email = new CakeEmail('default');
$email->template('test');
$email->emailFormat('html');
$email->to(array('john_doe#example.com' => 'John Doe'));
$email->subject('Test E-mail');
$email->helpers(array('Html', 'Text'));
$email->viewVars(
array(
...
)
);
if ($email->send()) {
$this->Session->setFlash('The e-mail was sent!', 'default', array('class' => 'alert alert-success'));
}
else {
$this->Session->setFlash('An unexpected error occurred while sending the e-mail.', 'default', array('class' => 'alert alert-error'));
}
I'd like to be able to capture the HTML rendered by the e-mail in a variable in addition to actually sending the e-mail. This way, I can record in the database the exact content of the e-mail's body. Is this doable?
Per line 50 of the MailTransport class, it appears the actual send() function returns the message and the header. So instead of:
if($email->send()) {
Try:
$mySend = $email->send();
if($mySend) {
//...
Then, $mySend should be an array:
array('headers' => $headers, 'message' => $message);
Thats what I do in my EmailLib:
https://github.com/dereuromark/tools/blob/2.0/Lib/EmailLib.php
it logs email attempts and captures the email output into a log file (email_trace.log) in /tmp/logs/ - if you are in debug mode it will only log (no emails sent - this has been proven quite useful for local delopment).
you can write a similar wrapper for your case.
but if you want to write it back into the DB Dave's approach seems to fit better.

Sending email to gmail with CodeIgniter displays "message sent" but there nothing in the inbox?

I'm following this amazing nettusts+ tutorial about sending a email to gmail.
It aparently worked. When I load the page it says: 'Your email was sent, fool.' but then I check my gmail and there's nothing there.
Does CodeIgniter take care of everything? Or I have to install smtp or something in my PC because I'm using localhost (LAMP in Ubuntu)?
Code:
/* SEND EMAIL WITH GMAIL */
class Email extends Controller {
function __construct()
{
parent::Controller();
}
function index()
{
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'janoochen#gmail.com',
'smtp_pass' => '***',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('janoochen#gmal.com', 'Alex Chen');
$this->email->to('janoochen#gmal.com');
$this->email->subject('This is an email');
$this->email->message('It is working. Great!');
if($this->email->send())
{
echo 'Your email was sent, fool.';
}
else
{
show_error($this->email->print_debugger());
}
}
}
I don't know if this is it, but in your code you've got #gmal.com instead of #gmail.com