I have a little issue. I'm using to send mail in my custom module this piece of code:
$content = 'Wiadomość testowa ąśźć';
$mail = Mage::getModel('core/email');
$mail->setToName($name);
$mail->setToEmail($email);
$mail->setBody($content);
$mail->setSubject($subject);
$mail->setFromEmail('test#test.com');
$mail->setFromName("Test");
$mail->setType('html');
try {
$mail->send();
Mage::getSingleton('customer/session')->setData('success',Mage::helper('adminhtml')->__('Your request has been sent'));
}
catch (Exception $e) {
Mage::getSingleton('customer/session')->setData('error',Mage::helper('adminhtml')->__('Unable to send email.'));
}
How can I set utf-8 charset before sending email in magento mail function. ?
I get email with no utf-8 charset in email body.
SOLVED
I created sendZendMail function in helper.
I used this function, instead Magento core/email:
public function sendZendMail($name,$email,$subject,$content){
$mail = new Zend_Mail('UTF-8');
$mail->setBodyHtml($content);
$mail->setFrom('your#frommail.com');
$mail->addTo($email, 'No reply');
$mail->setSubject($subject);
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Mail was sucessfully send.');
}
catch(Exception $ex) {
Mage::getSingleton('core/session')->addError('Unable to send email.');
}
}
kristoff, I had the same issue before with Portuguese, which also has special characters. I've sorted it out by using the function htmlentities() for accented words. The Zend Mail Object is a bit retarded. I hope it helps.
Related
If I am sending the email to "test+10#gmail.com", it will still send to "test#gmail.com"
Here is my code, please tell me what I'm doing wrong?
$single_email = $this->single_email;
try {
Mail::send('welcome_mail',['user'=>$single_email], function($message) use($single_email) {
$name = "Name";
if($single_email->first_name){
$name = $single_email->first_name;
}
$message->to($single_email->email,$name)
->subject("Subject")
->from('from#gmail.com',"From")
->replyTo('replyto#gmail.com',"Reply to");
});
MailSend::where('id',$single_email->id)->update(['is_sent'=>3]);
} catch (\Exception $e) {
MailSend::where('id',$single_email->id)->update(['error'=>$e->getMessage()]);
}
Thanks.
That is how emails work. Gmail and most providers allow you multiple "sibling" emails by appending + to the end. For example, test+1#gmail.com and test+stackoverflow#gmail.com will both end up at test#gmail.com - One of many things people use this is to track which service leaked your email. E.g. test+facebook#gmail.com, if you start getting spam emails to test+facebook#gmail.com, you will know they revealed it.
So, there is nothing wrong with your code.
I have an external WebSocket link where im getting data. My requirement is to receive those data in laravel controller and handle them.
How to listen in controller.
Finally i found the solution.
this has helped me.
$clientWebSoket = new \WebSocket\Client(
'wss://somelink'
);
$clientWebSoket->send(
'{"method":"test","symbols":"some data"}'
);
while ($i) {
try {
$message = $clientWebSoket->receive();
dump($message);
} catch (\WebSocket\ConnectionException $e) {
dd($e);
}
}
$clientWebSoket->close();
There was a problem with the subscription.
this is the message I get after I enter an email. When I go to the admin panel the email is added.
I would like it NOT to display this message. any suggestions please
The only place in Magento that error string occurs is in the following try/catch block
#File: app/code/core/Mage/Newsletter/controllers/SubscriberController.php
try {
//...snip!...
}
catch (Mage_Core_Exception $e) {
$session->addException($e, $this->__('There was a problem with the subscription: %s', $e->getMessage()));
}
catch (Exception $e) {
$session->addException($e, $this->__('There was a problem with the subscription.'));
}
Since you reported the error message as "There was a problem with the subscription.", that means the newsletter subscription code is throwing some sore of PHP exception, caught by the catch (Exception $e) { block. Magento does not output the messages from PHP exceptions. If I was in your position I'd temporarily change the exception handling code to include the error message
$session->addException($e, $this->__('There was a problem with the subscription. ' . $e->getMessage()));
This will let you track down the PHP error that's triggering your error message.
Per the comment below, the only place the "Cannot set standard header from addHeader()" exception error exists is
#File: lib/Zend/Mail.php
$prohibit = array('to', 'cc', 'bcc', 'from', 'subject',
'reply-to', 'return-path',
'date', 'message-id',
);
if (in_array(strtolower($name), $prohibit)) {
/**
* #see Zend_Mail_Exception
*/
#require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception('Cannot set standard header from addHeader()');
}
$value = $this->_filterOther($value);
$value = $this->_encodeHeader($value);
$this->_storeHeader($name, $value, $append);
return $this;
My guess is somewhere in your system someone's added some custom code that tries to set one of the standard email headers via the addHeader method.
I'm using codeigniter email function for sending mail.
Here is the code.
$this->email->to($to);
$this->email->subject($subject);
$this->email->attach($_FILES['attachments']['tmp_name']);
$this->email->message($mailcontent);
if($this->email->send())
{
return true;
}
when I printed the content just before sending it like this, I found its fine till there.
$this->email->message($mailcontent);
print_r($mailcontent);exit;
if($this->email->send())
{
return true;
}
But the mail I'm getting is empty.It has subject but the body is empty.
Why is this happening ?
Thanks #Niloy Saha.. I found that this happens when I tried to send mail without attachment.So I just put the code for adding attachment in an if condition and it worked.
if($_FILES['attachments']['tmp_name'])
{
$this->email->attach($_FILES['attachments']['tmp_name']);
}
$this->email->message($mailcontent);
if($this->email->send())
{
return true;
}
Firstly load the email library:
$this->load->library('email');
Secondly just after sending the mail check:
if($this->email->send()){
echo $this->email->print_debugger();die;
}
I have a little problem here, when I try to send an email using swiftmailer, I got an error.
Here's my code:
<?php
session_start();
include("config.php");
$dir = dirname(__FILE__);
$session = $_SESSION[serialize];
// Load the SwiftMailer files
require_once($dir.'/swift/swift_required.php');
$hold = 'TIDAK';
// Kondisi - Kondisi yang ada
if($_GET[phase]=='confirm'){
$to = "test#127.0.0.1";
$kalimat = "Invoice Dengan nomor ".$_GET[nosc]." Telah di confirm, mohon di cek di sistem";
$kalimat2 = "Berikut terlampir data Invoice Customer , mohon di pastikan.";
$title = "CONFIRMATION NOTIFICATION";
}
// Convert string dlu
$mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer
$message = Swift_Message::newInstance()
->setSubject($title) // Message subject
->setTo(array($to)) // Array of people to send to
->setBcc(array($bcc)) // Bcc:
->setFrom(array($_SESSION[mailadmin] => $_SESSION[namauser].''.store('namasite'))) // From:
->setBody($kalimat, 'text/html'); // Attach that HTML message from earlier
// Send the email, and show user message
if($hold<>'YA'){
if ($mailer->send($message)){
echo json_encode(array('success'=>true));
} else {
echo json_encode(array('success'=>false));
}
}
?>
And then when I try to post the data to this file through jquery I got an error, this error I got from firebug.
<br />
<b>Fatal error</b>: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [] does not comply with RFC 2822, 3.6.2.' in C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php:319
Stack trace:
#0 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php(249): Swift_Mime_Headers_MailboxHeader->_assertValidAddress(NULL)
#1 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php(107): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array)
#2 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php(71): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array)
#3 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\SimpleHeaderFactory.php(74): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array)
#4 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\SimpleHeaderSet.php(87): Swift_Mime_SimpleHeaderFactory->createMailboxHeader('Bcc', Array)
#5 C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime in <b>C:\xampp\htdocs\Colosus\core\swift\classes\Swift\Mime\Headers\MailboxHeader.php</b> on line <b>319</b><br />
So guys, anybody can help me here? I really doesn't know what happening here.
It's better if you use a try/catch around the send instruction:
try {
if ($mailer->send($message)){
...
}
} catch (Exception $e) {
$log_error->write_error($e->getMessage() . ';');
}
Or if you validate the email before sending it:
if(!Swift_Validate::email($email)){ //if email is not valid
//do something, skip them or log them
$log_error->log($email);
}
Please make sure there is no white space before or after the email address given.