Sending template emails in Magento - email

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.

Related

Symfony 4 + Api platform Cannot validate values of type \"NULL\" automatically. on nativeSQL query

i have been stuck for few hours with this:
Doing a simple query on my Variation base :
$query = "UPDATE variation SET status = 'FALSE' WHERE id IN
('ba21ac3f-0e7f-4bb9-b31f-dbd49053002e','a656e102-0339-4db0-a4b1-16451c2f1d90','64da7d32-2c9f-4478-bc6d-0b7b6c07af8e','8aba2925-7017-4899-bdfa-bf341c0fccec','6d4374cb-3713-4162-be53-2232202b5809','1810057a-6157-45bf-85d5-ade282b7d807','967d7495-6e93-4530-b6d8-d23640b39226','ebdcd88f-1f58-44b6-a14d-d0db9a564671')";
$result = $this->entityManager->getConnection()->prepare($query);
$result->execute();
And using postman it's returning me :
"#context": "/contexts/Error",
"#type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "Cannot validate values of type \"NULL\" automatically. Please provide a constraint."`
my variation class:
/**
* #var bool
*
* #ORM\Column(type="boolean")
*
* #Groups({"variation"})
*/
protected $status;
How comes it try to validate somethings. Ps the query is fully working ( POSTGRES - Symfony 4.2 - PHP72 )
If body content is empty in request, its possible to correct that if content type are is also empty in header request

I need to know how to disable the CSRF function in Impresspages cms

I need to know how to disable the CSRF function in Impresspages cms. i saw a possible answer provided on a previous thread, but wasnt fully sorted. When my customer logs into my impress pages site at: cleanwaterpartnership.co.uk, he gets an "ERROR undefined" message. In the log files on the cms system it states:
Core.possibleCsrfAttack.
The notes say:
array(1) {
["post"]=>
array(6) {
["securityToken"]=> string(32) "b2766e9f8578bf04d456952a35882bb4"
["antispam"]=> array(2) { [0]=> string(0) "" [1]=> string(32) "ea3810b9e1da7fdaffe4003836be0541" }
["sa"]=> string(15) "Admin.loginAjax"
["global_error"]=> string(0) ""
["login"]=> string(16) "Alastair Stewart"
["password"]=> string(16) "XXXXXXXXX" }
}
Use PublicController type. https://www.impresspages.org/docs/controller
This type of controller doesn't do any checks.

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;
}

Zend_Mail will not send bcc to sender address

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