Bcc in email not working in Yii framework - php

I want to send copy of mail to given mail address (Bcc), but it's not sending copy of it (Bcc) not working however mail sent successfully.
I am using Yii framework and code something like
$email = Yii::app()->email;
$email->to = $modelVar->user->email;
$email->subject = 'Registration Confirmation';
$email->bcc= 'to-admin#gmail.com'; // Not working
$email->view = 'reg-view-here';
$email->viewVars = array('vars' => $modelVar);
$email->send();

If Yii is using phpmailer then try:
<?php
$mailer->addBCC('foo#example.com');

Related

add e-mail recipient into php script

CC or forward is not possible to set on mailserver for authorisation mail sent by Joomla itself, but we'd like to store these e-mails.
Question is: how to set it in php of specific plugin? (plugin is sending these e-mails)
code:
// send auth email to user who signed ...
if ($signature_verification = (int)$this->settings->get('security.signature_verification', 0)) {
// unpublished, visitor must verify it first
$this->db->set('published', 0);
$config = JFactory::getConfig();
$from = $config->get('mailfrom', '');
$fromname = $config->get('fromname', '');
$recipient = (string)$this->db->get('email', '');
When I replace last line wth: $recipient = ('my#email.com'), then I get that message, but i want one for visitor and copy for me.
Thanks for advice
OK, actually this piece of code initiates sending of that mail:
if (
$this->sendMail(
$from,
$fromname,
$recipient,
$subject,
$body
) !== true
) {
throw new phpmailerException(JText::_('PLG_CONTENT_CDPETITIONS_EMAIL_SEND_FAILED'), 500);
}
When I make copy of that code, paste it below, and replace $recipient with my e-mail, it works: I have the same message delivered on both adresses. But I need it have it like CC (carbon copy) and have original recipient adress in header of mail, which is delivered to me.
Use the built in mailer methods for Joomla:
$msg = "This is my email message.";
$subject = "Database Update Email";
$to = (string)$this->db->get('email');
$config = JFactory::getConfig();
$fromemail = $config->get('mailfrom');
$fromname = $config->get('fromname');
$from = array($fromemail,$fromname);
$mailer = JFactory::getMailer();
$mailer->setSender($from);
$mailer->addRecipient($to);
$mailer->addRecipient('you1#yourdomain.com');
$mailer->addRecipient('you2#yourdomain.com');
$mailer->addCC('you3#yourdomain.com');
$mailer->addBCC('you4#yourdomain.com');
$mailer->setSubject($subject);
$mailer->setBody($msg);
$mailer->isHTML();
$mailer->send();
This should use PHP to send an HTML email to whomever you want and copy other users on the email through either direct send, CC, or BCC depending on which method you use.

Sending PHP emails with HTML/CSS

I'm trying to send emails with PHP. I would like to add some style with CSS (no matter if inline, internal or with external file).
I've tried PHPmailer, but it fails to recognize some elements (such as body), media queries (#media) and declarations (max-width, inline-block, etc...). I'm now trying to use SwiftMailer, but online documentation doesn't mention anything about styling.
Just for sake of clarity, here's the snippet I would like to use: JsFiddle
Any ideas to send PHP emails with working HTML/CSS?
You could use a CSS inliner tool like http://templates.mailchimp.com/resources/inline-css/
to convert your 'normal' template (made like a normal HTML page) to an email-friendly template. This is needed because mail clients doesn't recognise separate elements.
I currently use a template based on the ones made available by Zurb, http://zurb.com/ink/
It also depends on the receiver's email client. Not all clients accept all css. Use a litmus test of some sort to check with different e-mail clients which css you can use. Tables often work with email clients, a lot of them don't accept divs I believe.
I use PHPMailer to send emails with PHP, and it never fails to recognize these elements (for me anyway).
To use it, i create a fonction :
function sendMail($name, $from, $message, $to, $subject)
{
$mail = new PHPMailer();
$body = "<html><head></head><body style=\"background-color: #F2F1F0;\"><p>".$message."</p></body></html>";
$mail->SetFrom($from, $name);
$mail->AddReplyTo($from, $name);
// Only if you want to send an attachment, send a variable $object to the function
//$mail->AddAttachment($object);
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress($to, $name);
if(!$mail->Send()) {
$result = $mail->ErrorInfo;
}
else
{
$result = "Mail sent successfully";
}
return $result;
}
And an exemple to use it :
// Preparation of the message
$message = '<p class="img"><img src="http://mywebsite.com/img/myImage.png" width="220px"></p>';
$message .= '<p class="txt">Hello Mr Dupond !</p>';
$message .= '<p class="txt">We are glad to have you among us</p>';
$message .= '<p class="txt">Se you soon on our Website !</p>';
$message = utf8_decode($message);
// variables needed
$name = "Mr Oktopuss";
$from = "contact#oktopuss.eu";
$to = "contactAddress#domain.ext";
$subject = "The subject of this mail !";
// Send the mail and receive the result
$result = sendMail($name, $from, $message, $to, $subject);
echo $result;
Maybe that could be help you

unable to send mail via php

I am trying to send mail using php.And i am using WampServer.
so i tried the following code
ini_set("SMTP","smtp.gmail.com" );
ini_set("smtp_port","465");
ini_set('sendmail_from', 'person1#gmail.com');
$to = "person2#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "person1#gmail.com";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
but it take more time to connect and says could not connect with localhost.
Please help me in solving the problem
try this configuration:
http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/
this might help.
somehow, instead of "smtp.gmail.com", for me it works with "ssl:smtp.gmail.com"
This line:
ini_set("SMTP","smtp.gmail.com" );
should be
ini_set("SMTP","ssl:smtp.gmail.com" );
Also, see this response to a similar question: Send email using the GMail SMTP server from a PHP page
You're trying to send mail from your localhost (Your PC) I guess It's not setup to send mail. Move the script to a production server and it will work

Joomla Send Mail with JUtility::sendMail sender email issue

I faced an issue in Joomla JUtility::sendMail function
The function arguments mentioned in the Joomla documentation is like this
The issue is i can't set the fromemail(Sender email).When i set the sender email and replay to email .The replay to email is showing in the mail is the one from joomla admin config email.
when i set the other email in replay to or sender email Its not taking correct one every time its using the email from joomla admin config.
I got one refference from google almost same but I tried this it not working.
I am using Joomla 1.7
I tried with
$your_email //can be array but here string one email
$your_name //name i will work fine
$user_email //admin email
$subject //subject
//last two argument is reply to and replay name Its showing inside mail but click on replay it will admin config email.
JUtility::sendMail($your_email, $your_name, $user_email, $subject, $fcontent,1,NULL,NULL,NULL,$your_email,$your_name);
Any help will appreciated..
Try like this
$mailer =& JFactory::getMailer();
//add the sender Information.
$sender = array(
$your_email,
$your_name
);
$mailer->setSender($sender);
//add the recipient.
$recipient = $user_email;
$mailer->addRecipient($recipient);
//add the subject
$mailer->setSubject('Your subject string');
//add body
$mailer->setBody($fcontent);
$send =& $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->message;
} else {
echo 'Mail sent';
}
It's done.For more information see this link Sending email from extensions.
I thinks it may help you.

I need to attach a file to an outbound email automatically...Help

I have one form (input.html) that's completed by people working in five different divisions of this business. When the form is submitted it posts to output.php.
Output.php does a number of things:
First it displays all of the input information to the screen as a completed form. (Just to show them their completed document).
It has also created a file called unique_file.html based on two of the input fields in input.html.
Next, output.php has sent an email to one of five email groups, based upon another input field selected in input.html.
Finally (for now), I need the unique_file.html to be an attachment to the email. That is my problem.
I have found scripts for uploading files, I have found many tutorials about uploading files, but I just want to attach the unique_file.html to my outgoing email and I am not seeing how that is done.
Can someone point me in the right direction as to where to start? I am certainly missing the boat on this one and I have probably seen it and not realized it.
If you can use the Zend_Framework you can easily attach file to an email i.e.
$mail = new Zend_Mail();
$at = new Zend_Mime_Part($myImage);
$at->type = 'image/gif';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = 'test.gif';
$mail->addAttachment($at);
$mail->send();
see the documentation,
You should be able to attach a file also by using Mail_Mime pear package and the normal mail function.
But I think the solution using the Zend framework is much more straight forward.
Cheers.
I find PHPMailer best for this. An example from their site:
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$address = "whoto#otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

Categories