I'm having problems sending attachments in mail with mailgun.
When I go to logs in mailgun, the mail sent shows :
"attachments": [],
Here's my code :
$location = Storage::get('attachments/'.$this-attachments->file_name);
return $this->markdown('emails.create',["desc" => $this->mail->description])
->subject($this->mail->subject)
->attach($location);
I got raw encoded codes when I return the $location so i tried doing with public_path() but the result was same( "attachments":[], <- in mailgun logs ).
Am i doing it wrong? How do i get the attachment in the mail? The mail is going through but not with attachments.
Thanks for your time.
Try below code with storage_path():
$location = storage_path('attachments/'.$this-attachments->file_name);
return $this->markdown('emails.create',["desc" => $this->mail->description])
->subject($this->mail->subject)
->attach($location);
You wrote
$location = Storage::get('attachments/' . $this-attachments->file_name);
But it should be
$location = Storage::get('attachments/' . $this->attachments->file_name);
You forgot the > in $this->
Related
Since today, many of my php applications can not send email using SwiftMailer and different Mandrill accounts.
I've got this code, and the send function in the last if stop the script..
// Instance message
$message = Swift_Message::newInstance();
$message->setSubject("subject")
->setFrom(array('noreply#email.test' => 'test'))
->setTo(array('a_valid_email' => 'name'))
->setBody("test", 'text/html')
->setPriority(2);
$smtp_host = 'smtp.mandrillapp.com';
$smtp_port = 587;
$smtp_username = 'valid_username';
$smtp_password = 'valid_password';
// SMTP
$smtp_param = Swift_SmtpTransport::newInstance($smtp_host , $smtp_port)
->setUsername($smtp_username)
->setPassword($smtp_password);
// Instance Swiftmailer
$instance_swiftmailer = Swift_Mailer::newInstance($smtp_param);
$type = $message->getHeaders()->get('Content-Type');
$type->setValue('text/html');
$type->setParameter('charset', 'iso-8859-1');
//Here the send function stop event and I did not go inside the if
if ($instance_swiftmailer->send($message, $fail)) {
echo 'OK ';
}else{
echo 'NOT OK : ';
print_r($fail);
}
Thank you in advance to help me to solve this problem..
If your code used to work, and now doesn't work, and you didn't change your code, then it's probably not a problem with your code. Check your Mandrill account validity - sometimes they suspend accounts for suspicious-appearing usage.
i have a big Problem. I'll fetch all mails of a mailbox with php_imap, connecting to pop3 service of an microsoft exchange server.
The Adress of the Mailbox: sample#sample.com
This Mailbox has many aliases: e.G. sample_test#sample.com, sample_test2#sample.com
My problem: When someone writes a mail to sample_test#sample.com the mail is deliverd to the mailbox. So far thats no Problem. When viewing the Header-Source in Microsoft Outlook it displays
To: Sample "sample_test#sample.com"
Still, no problem!
But ...
after receiving this via my php-script and writing the imap_header and imap_body to the file e.G. mail1.eml viewing the source gives me
To: Sample "sample#sample.com"
Here i wish to get
To: Sample "sample_test#sample.com"
My Code:
Heres the Snippet for Understanding how i save this to eml file ...
$mailbox = '{'.$imapHost.':'.$imapPort.'}INBOX';
$imapStream = imap_open($mailbox, $imapUser, $imapPassword, 0, 1, array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));
$hdr = imap_check($imapStream);
$overview = imap_fetch_overview($imapStream, "1:$mailCount");
$size = count($overview);
for($i=$count-1;$i>=0;$i--) {
-->$headers = imap_fetchheader($imapStream, $i, FT_PREFETCHTEXT);
-->$body = imap_body($imapStream, $i);
-->file_put_contents($fullPath . '/' . $saveemlfile, $headers . "\n" . $body);
}
imap_close($imapStream);
Thanks for your Help!
Im using the below php code to send an email to one address and bcc 2 other addresses. It sends to the recipient fine but I can only get it to send to one of the 2 bcc addresses. (see comments in code for what ive tried)
Oddly enough though, $result comes back as 3 so it seems that its trying to send the second bcc email but it never comes through.
<?php
$tracker='tracking#pnrbuilder.com';
$subject = $_POST['subject'];
$sender = $_POST['sender'];
$toEmail=$_POST['toEmail'];
$passedInEmail=stripslashes($_POST['message']);
$passedInEmail=preg_replace('/ /',' ',$passedInEmail);
require_once('swiftLib/simple_html_dom.php');
require_once('swiftLib/swift_required.php');
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = Swift_Message::newInstance();
//turn the meesage into an object using simple_html_dom
//so we can iterate through and embed each image
$content = str_get_html($passedInEmail);
// Retrieve all img src tags and replace them with embedded images
foreach($content->find('img') as $e)
{
if($e->src != "")
{
$value = $e->src;
$newValue = $message->embed(Swift_Image::fromPath($value));
$e->src = $newValue;
}
}
$message->setSubject($subject);
$message->setFrom($sender);
$message->setTo($toEmail);
//this is my problem
$message->setBcc(array('tracking#pnrbuilder.com',$sender));
//as it is above only "sender" gets the email
//if I change it like this:
//$message->setBcc($tracker,$sender);
//only "tracker" gets the email
//same if I change it like this:
//$message->setBcc($sender);
//$message->addBcc($tracker);
$message->setReplyTo(array('flights#pnrbuilder.com'));
$message->setBody($content,'text/html');
$result = $mailer->send($message);
if ($result=3) {
echo 'Email Sent!';
}
else {
echo 'Error!';
}
?>
What is the proper way to do this?
You can find the swiftmailer tutorial here
example:
$message->setBcc(array(array('some#address.tld' => 'The Name'),array('another#address.tld' => 'Another Name')));
Try setting the names for the email addresses and see if it makes any difference.
This ended up being an issue on the server side, I contacted my hosting provider (GoDaddy) who were able to make some changes on their end fixing the problem. Thank you to all those who tried to help!
I'm using PHPMailer to send customers receipt of their order in a pdf format. PDF creation works like a dream, but it just wont attach it to mail. I've tried to my gmail and my own servers email, but it wont send the attachment. Here's my code:
<?php
//Lähetä tilausvahvistus
require_once('mail/class.phpmailer.php');
$bodytext = '
Olemme vastaanottaneet tilauksenne '. $ordernumber .'.
Tilaamanne tuotteet löytyvät liitteestä.'
;
$email = new PHPMailer();
$email->From = 'no-reply#xxx.fi';
$email->FromName = 'no-reply#xxx.fi';
$email->Subject = 'Olemme vastaanottaneet tilauksenne ' . $ordernumber;
$email->Body = $bodytext;
$email->AddAddress('christian.nikkanen#gmail.com');
$email->AddAttachment('kuitit/kuitti777.pdf','kuitti777.pdf');
return $email->Send();
?>
I've tried relative path and direct path, but no, it wont send.
Have you validate your path correctly?
Try to write your path again using $_SERVER['DOCUMENT_ROOT']
check that PHP is interpreting your path to the file correctly. Try sticking the $pathtofile in a session and using that rather than statically assigning (or dumping it to output) so you can ensure it isn't a simple path issue.
I using cakephp email component. In my live server $this->Email->send() return success. but mail is not receiving. what is the problem?? i need to find whats the error ?
My controller not have any model this may cause any problem for emails ?
$this->Email->from = 'Mysitename <no-reply#mysite.com';
$this->Email->to = 'sample#gmail.com';
$this->Email->subject = "This is test";
$this->Email->template = 'template_name';
$this->Email->sendAs = 'html';
ob_start();
if($this->Email->send())
{
$this->log(' Mail Success');
}
else
{
$this->log('Something broke in mail');
}
ob_end_clean();
You can set delivery to debug to see an output of your message to make sure it's fine:
$this->Email->delivery = 'smtp';
And you also need to setFlash('email') to see the output in your view:
echo $this->Session->flash('email');
As far as emailing from a live server goes - there's a very good chance the server or IP is blacklisted and you'll need to get it to pass various checks before your sent messages can be received:
http://www.digitalsanctuary.com/tech-blog/debian/setting-up-spf-senderid-domain-keys-and-dkim.html