Send Email Only when radio option is Selected
-
14-11-2019 - |
Question
I am modifying a registration form to include two radio buttons for the account type the customer is applying for. So I have two new buttons: Personal Account [] Corporate Account [].
If the customer selects personal account, value "1" is saved to a new column in my customer table (account_type), and if corporate account is selected, the value "0" is saved. Now, what I want to do is to modify the code below that sends an email to admin every time a new customer registers so that it sends an extra email if a customer has applied for a Corporate account.
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($data['email']);
$mail->setFrom($this->config->get('config_email'));
$mail->setSender($this->config->get('config_name'));
$mail->setSubject($subject);
$mail->setText($message);
$mail->send();
**// Send to main admin email if new account email is enabled**
if ($this->config->get('config_account_mail')) {
$mail->setTo($this->config->get('config_email'));
$mail->send();
// Send to additional alert emails if new account email is enabled
$emails = explode(',', $this->config->get('config_alert_emails'));
foreach ($emails as $email) {
if (strlen($email) > 0 && preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $email)) {
$mail->setTo($email);
$mail->send();
}
}
}
The code above after "//send to main admin if new account email is enabled" just sends a simple email to admin saying someone new has registered. I want to keep that, but I would like to send the extra email if someone is applying for a corporate account. I guess I just need to use an if statement to check whether account_type=0 but I am not an expert and I don't know how to integrate that to the existing code. I hope I have explained myself well. By the way, all this code is from Open Cart, open-source e commerce system.
Solution
you can use if condition like
if(isset($_POST['ur_radio_ele_name']) && $_POST['ur_radio_ele_name']!=''){
// your code to send mail
}
if $_POST['ur_radio_ele_name']
is set and not null then only it would send mail, otherwise it wont.