Can I create a function to change sender email address from admin to customer email in Wordpress. I added below to function.php, but it doesn't work.
If I see wpform or contact form7 has the ability to sen email from customer email address but woocoomerce doesn't have that.
function custom_new_order_email_sender( $email_from, $email ) {
// Check if the email is a new order email
if ( 'new_order' === $email->id ) {
// Get the order ID from the email
$order_id = $email->object->get_id();
// Get the customer email from the order
$customer_email = get_post_meta( $order_id, '_billing_email', true );
// Set the email from address to the customer email
$email_from = $customer_email;
}
return $email_from;
}
add_filter( 'woocommerce_email_from_address', 'custom_new_order_email_sender', 10, 2 );
I tried adding the filter option to function.php
Related
Using Codeigniter 3, I have a web form that sends an email to the site admin once a form is submitted - this works as expected.
I am using email templates, once the form is submitted template 1 is sent (to the site admin). I would now like to simultaneously send template 2 (to the submitter's email address).
The emails will contain the same content apart from the email intro text, and subject - details below;
Email Template 1 - to admin;
'Hi, a new item has been requested on the site, ...'
Email Template 2 - to submitter;
'Hi, Here is the item you have requested on the site, ...'
My current code is as follows;
public function sendRequest() {
$this->load->library('email');
$from_email = $this->input->post('email');
$to_email = 'admin#example.com';
$subject = 'New Item Request - Admin Copy';
$name = $this->input->post('name');
$comment = $this->input->post('comment');
$this->email->from($from_email);
$this->email->to($to_email);
$this->email->subject($subject);
$data = array(
'name' => $name,
'from' => $from_email,
'comment' => $comment,
);
// send email template 1
$this->email->message($this->load->view('template/email/item_request_template', $data, true));
// send email template 2 to submitter - how?
// change $subject to 'New Item Request - User Copy';
if($this->email->send()) {
// send the $data to my email template
$data = array(
'item_request_name' => $this->input->post('name'),
'item_request_email' => $this->input->post('email'),
'item_request_comment' => $this->input->post('comment'),
);
}
}
Is there a more efficient way of doing this?
You simply have to repeat all the steps required for sending an email in the first place. Only difference is that for the second call you need to call, and reset all the required config options.
public function sendRequest() {
$this->load->library('email');
$from_email = $this->input->post('email');
$to_email = 'admin#example.com';
$subject = 'New Item Request - Admin Copy';
$name = $this->input->post('name');
$comment = $this->input->post('comment');
$this->email->from($from_email);
$this->email->to($to_email);
$this->email->subject($subject);
$data = array(
'name' => $name,
'from' => $from_email,
'comment' => $comment,
);
// send email template 1
$this->email->message($this->load->view('template/email/item_request_template', $data, true));
// send email template 2 to submitter - how?
// change $subject to 'New Item Request - User Copy';
if($this->email->send()) {
$this->email->clear(TRUE); // Pass TRUE as an argument if you are sending attachments
$this->email->from($from_email); // Update for second email
$this->email->to($to_email); // Update for second email
$this->email->subject($subject); // Update for second email
// send the $data to my email template
$data = array(
'item_request_name' => $this->input->post('name'),
'item_request_email' => $this->input->post('email'),
'item_request_comment' => $this->input->post('comment'),
);
$this->email->message($this->load->view('template/email/item_request_template_2', $data, true));
$this->email->send();
}
}
I send e-mails with ews-php library (exchange 2013) and try to set custom sender's name.
I use the code from the official api: http://jamesarmes.com/php-ews/doc/0.1/examples/email-send.html
$fromAddress = new EWSType_EmailAddressType();
$fromAddress->EmailAddress = 'email#server.de';
$fromAddress->Name = 'From Name';
$msg->From = new EWSType_SingleRecipientType();
$msg->From->Mailbox = $fromAddress;
So it should look like "From Name <email#server.de>". Instead it's "Email <email#server.de>"
Any ideas what went wrong?
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.
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.
Below is the code
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('config.php');
// table name
$tbl_name="temp_members_db";
// Random confirmation code
$confirm_code=md5(uniqid(rand()));
// values sent from form
$name=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];
// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password, country)VALUES('$confirm_code', '$name', '$email', '$password', '$country')";
$result=mysql_query($sql);
// if suceesfully inserted data into database, send confirmation link to email
if($result){
// ---------------- SEND MAIL FORM ----------------
// send e-mail to ...
$to=$email;
// Your subject
$subject="Your confirmation link here";
// From
$header="from: your name <your email>";
// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
//$message.="http://www.yourweb.com/confirmation.php?passkey=$confirm_code";
$message.="http://localhost/confirmation.php?passkey=$confirm_code";
// send email
$sentmail = mail($to,$subject,$message,$header);
}
// if not found
else {
echo "Not found your email in our database";
}
// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>
Some mailservers ( IE MailEnable ) aint handling the FROM correctly
a fix would be this
$header="FROM: your name <your email>";
To
$header="FROM: your email";
whats the error you are getting and i think you try to send a email , if a mail server is not configured in local host you cant send emails
you can use a SMTP class to send mails using your SMTP mails like gmail