Zend_Mail will not send bcc to sender address - zend-framework

I have a problem, when I want to send mail to a customer and also to the admins.
The problem is, that the customer receives the mail, but the bcc will not if the from = bcc. Is there any setting I have missed?
Could this be a server issue, or a Zend related one?
Example code I use:
$mail = new Zend_Mail();
$mail->setFrom( 'admin#example.com', 'Admin' )
->addTo( 'customer#anydomain.com', 'Customer' )
->setBodyText( 'Example' )
->addBcc('admin#example.com');
$mail->send();
The headers are (from $mail->getHeaders()):
array(3) {
["From"]=>
array(2) {
[0]=>
string(26) "Admin <admin#example.com>"
["append"]=>
bool(true)
}
["To"]=>
array(2) {
[0]=>
string(25) "Customer <customer#anydomain.com>"
["append"]=>
bool(true)
}
["Bcc"]=>
array(2) {
[0]=>
string(18) "admin#example.com"
["append"]=>
bool(true)
}
}

I stumbled on this post while working on using Zend_Mail to send a bcc to the sender address and found that for me the following does in fact work:
$fromName = 'admin';
$fromMail = 'sender#mail.com';
$mail = new Zend_Mail();
$mail->setFrom($fromEmail, $fromName);
$mail->addBcc($fromMail);
Even though the bug report http://framework.zend.com/issues/browse/ZF-8723 as linked in RakeshS's post is still marked as unresolved. My Zend version is:
const VERSION = '1.11.12';
It would be interesting to learn whether the problem would also be solved for the original posters for the updated Zend framework, if they may happen to read this

I'm getting the same behavior as you. The sender is not getting the message if the address is added as Bcc. So, it's likely to be a Zend Mail related issue (I don't think we have the same server configuration).

There is a bug added to ZF which almost similar to this issue: http://framework.zend.com/issues/browse/ZF-8723
BTW, you could also get BCC to work with the help of Zend Mail Add Header method. Please try the following work-around:
$mail->addHeader('Bcc', 'admin#example.com');

if you use only Bcc recipients without TO
read this
http://framework.zend.com/issues/browse/ZF-3509

Related

How to control tracking options and tags when using Mailgun's SMTP option (i.e. not using their API)

I’m using python to send emails using Mailgun’s SMTP server. I wish to use Mailgun’s builtin ability to tag my messages, and to track open and click events.
I know this can be done using Mailgun’s send message API, by adding headers like o:tag, o:tracking, o:tracking-clicks and o:tracking-opens (as explained here: https://documentation.mailgun.com/en/latest/api-sending.html#sending)
However, seeing as I'm the SMTP gateway and not the API, I’m trying to understand how to achieve the same result - emails that are tagged and fully tracked in Mailgun.
Any thoughts on how it can be done?
This is my little script at the moment:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Found it!
The following X-Mailgun headers can be added:
https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-smtp
So my script would be:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
message["X-Mailgun-Tag"] = "<tag>"
message["X-Mailgun-Track"] = "yes"
message["X-Mailgun-Track-Clicks"] = "yes"
message["X-Mailgun-Track-Opens"] = "yes"
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Now my email is tagged (can be analysed on a tag level in Mailgun), and clicks are tracked.
Happy days!

Mantis Bug Tracker SOAP API Response XML Error

I am using Mantis Bug Tracker SOAP API, but unfortunately every time it returns to me message like
"looks like we got no XML document",
after tracing the last response I got following message
"<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><SOAP-ENV:Fault><faultcode xsi:type="xsd:string">Client</faultcode><faultactor xsi:type="xsd:string"></faultactor><faultstring xsi:type="xsd:string">Issue does not exist.</faultstring><detail xsi:type="xsd:string"></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>"
I hope that, I am getting xml respose back, it appears that there is a addition of "" characters in the beginning.
Any clue or help would be great, in removing those characters.
The code for connecting to MANTIS SOAP API SERVER
<?php
$c = new \SoapClient("http://dev06/api/soap/mantisconnect.php?wsdl", array('trace'=> true, 'encoding'=>' UTF-8', 'soap_version'=>1.2));
$username = "xxxxx";
$password = "xxxxx";
try {
$c->mc_issue_get(trim($username), trim($password), 2331);
} catch (SoapFault $exception) {
var_dump($c->__getLastResponse());
}
?>
I don't see any issue with your code and it works perfectly in my environment with slight modifications:
$c = new \SoapClient("http://localhost/demo/mantisbt-1.2.15/api/soap/mantisconnect.php?wsdl", array('trace'=> true, 'encoding'=>' UTF-8', 'soap_version'=>SOAP_1_2));
$username = "XXXXXXXX";
$password = "XXXX";
try {
$issue = $c->mc_issue_get(trim($username), trim($password), 31);
var_dump($issue);
} catch (SoapFault $exception) {
var_dump($c->__getLastResponse());
}
It could be the soap_version, so may be you could try with soap_version=SOAP_1_1
Oh...!
Finally got the solution for it. Its very simple.
Firstly mantis SOAP API code base contains may be more than 20,000 lines of code. I think there is some where some one is printing some BOM characters.
So best solution would be, just use following function,
ob_clean();
This function must be used in
/library/nusoap/nusoap.php
Because this file has
send_response()
That printouts payload, So just use ob_clean() at the beginning of the send_response() function.
Thanks and hope it will help others.

Send email codeigniter function returns "Recipient address rejected: Domain not found" instead of false

I'm using codeigniter. I test to send an email to a wrong inexistant address like t#t.com.
My code is just a method of the controleur like that :
function test() {
$this->email->from('mymail#gmail.com');
$this->email->to(htmlentities("t#t.com"));
$this->email->subject('test');
$this->email->message("Just a test !");
$r = $this->email->send();
if (!$r)
echo "not sent, wrong email";
else
echo "sent";
}
Basically, the send() function returns true or false. But it doesn't work ! The error message I got is as following :
A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: SMTP server response: 550 5.1.2 <t#t.com>: Recipient address rejected: Domain not found
Filename: libraries/Email.php
Line Number: 1540
not sent, wrong email
I have the message, so send() function replies false but I also have the error message, which I don't want !
It's a blocking point. Anyone has an idea why send() function doesn't return the true or false reply ?
thanks by advance !
a quick and dirty hack to get rid of the error is to prepend the mail function with '#':
$r = #$this->email->send();
I've tried it and it works as it should, I get: not sent, wrong email.
What version of CI are you using? make sure it's the last one.
Just in case, check the Email.php library under system/libraries in your CI folder
protected function _send_with_mail()
{
if ($this->_safe_mode == TRUE)
{
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
{
return FALSE;
}
else
{
return TRUE;
}
}
else
{
// most documentation of sendmail using the "-f" flag lacks a space after it, however
// we've encountered servers that seem to require it to be in place.
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
{
return FALSE;
}
else
{
return TRUE;
}
}
}
Check that the function _send_with_mail() inside looks exactly like the one above

malformed email subject header when subject > 75 chars using codeigniter email lib

I'm getting some garble in my MIME headers when the subject is over 75 chars.
When the line break is encoded in the header there is an extra line break that is invalid.
Some email gateways are bouncing the email with a "Malformed MIME field: ?= =?utf-8?Q?SUBJECT?=" error.
Does anyone have any experience with utf-8 problems sending emails with CodeIgniter?
-snip-
Return-Path: ***
Subject: =?utf-8?Q?SUBJECT_LINE <--
?= <-- Problem in Subject header
=?utf-8?Q?SUBECT_LINE_2?= <--
To: ***
Reply-To: ***
-snip-
Update:
This has nothing to do with gmail smtp. I have rewritten the question in the hope that it will help someone out in the future.
Apparently this is a known issue, caused by Subject lines > 75 chars.
http://codeigniter.com/forums/viewthread/154493/P15/#925385
The fix was to change the email config like this:
$config['newline'] = "\r\n";
$config['crlf'] = "\n";
Since I myself had this exact problem I will share the solution here since the one shared does not work with version 2.2
Find this piece of code located in system/libraries/Email.php:365
public function subject($subject)
{
$subject = $this->_prep_q_encoding($subject);
$this->_set_header('Subject', $subject);
return $this;
}
With this one
public function subject($subject)
{
$subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
$this->_set_header('Subject', $subject);
return $this;
}

Sending template emails in Magento

I'm creating a Magento Module that can be used to send emails in certain occasions of my website. I'm following the tutorial from Branko Ajzele and everything seems to work fine until I try to send the email where I get a false response from the Send function.
Below is the code I'm using along with the result returned:
public function sendAction() {
/*
* Loads the html file named 'custom_email_template1.html' from
* app/locale/en_US/template/email/activecodeline_custom_email1.html
*/
$emailTemplate = Mage::getModel('core/email_template')
->loadDefault('custom_email_template1');
// var_dump(Mage::getModel('core/email_template'));
//Create an array of variables to assign to template
$emailTemplateVariables = array();
$emailTemplateVariables['myvar1'] = 'Branko';
$emailTemplateVariables['myvar2'] = 'Ajzele';
$emailTemplateVariables['myvar3'] = 'ActiveCodeline';
/**
* The best part <img src="http://inchoo.net/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley">
* Opens the activecodeline_custom_email1.html, throws in the variable array
* and returns the 'parsed' content that you can use as body of email
*/
/*
* Or you can send the email directly,
* note getProcessedTemplate is called inside send()
*/
$emailTemplate->setSenderName('my name');
$emailTemplate->setSenderEmail('example#domain.com');
$emailTemplate->setTemplateSubject('STATUS CHANGED');
var_dump($emailTemplate->send('example#domain.com'));
echo "<br>";
var_dump($emailTemplate);
exit("test");
}
The var_dump given by var_dump($emailTemplate); returns the object with all the information correctly as shown below:
bool(false)
object(Gp_Notify_Model_Email_Template)#82 (19) { ["_templateFilter:protected"]=> NULL ["_preprocessFlag:protected"]=> bool(false) ["_mail:protected"]=> NULL ["_designConfig:protected"]=> NULL ["_emulatedDesignConfig:protected"]=> bool(false) ["_initialEnvironmentInfo:protected"]=> NULL ["_eventPrefix:protected"]=> string(13) "core_abstract" ["_eventObject:protected"]=> string(6) "object" ["_resourceName:protected"]=> string(19) "core/email_template" ["_resource:protected"]=> NULL ["_resourceCollectionName:protected"]=> string(30) "core/email_template_collection" ["_cacheTag:protected"]=> bool(false) ["_dataSaveAllowed:protected"]=> bool(true) ["_isObjectNew:protected"]=> NULL ["_data:protected"]=> array(6) { ["template_type"]=> int(2) ["template_subject"]=> string(14) "STATUS CHANGED" ["template_text"]=> string(208) "
ActiveCodeline custom email example by Branko Ajzele
Hi there {{var myvar1}} {{var myvar2}} from {{var myvar3}}. This is just some example template to test custom email module.
" ["template_id"]=> string(22) "custom_email_template1" ["sender_name"]=> string(7) "my name" ["sender_email"]=> string(15) "phil#gproxy.com" } ["_hasDataChanges:protected"]=> bool(true) ["_origData:protected"]=> NULL ["_idFieldName:protected"]=> NULL ["_isDeleted:protected"]=> bool(false) } test
The thing is that although everything seems to go well the send function returns false and of course I never get to receive the email.
Is there something I'm forgetting to do like any configuration in the backend or something?
---- UPDATE ----
After some investigation I realized that there are no emails reaching their destination at all in my Magento installation which I thought they were, so figured I should start from there.
I have already added all the emails in the backend.
I checked the Locale (language) and changed it to english/US (which I read could be an issue).
Any advise?
Are u trying it on the localhost or the live site. If you are trying in the localhost then you need to correct in the php.ini file for the email setting.