/    Sign up×
Community /Pin to ProfileBookmark

How to send auto generated mail to user based on radio button selection

Hello,

I am new to php. I have created an html form where the user selects any one option from the radio button. Every option has a price that user will be paying if he orders. What I want is to send that price to the user as auto generated mail when the user submits the form. My html is as follows:

<input type=”radio” name=”grade” class=”form-control” required><img src=”images/grade_2.png” alt=”no image”>&nbsp;
<input type=”radio” name=”grade” class=”form-control” required><img src=”images/grade_3.png” alt=”no image”>&nbsp;
<input type=”radio” name=”grade” class=”form-control” required><img src=”images/grade_4.png” alt=”no image”>&nbsp;
<input type=”radio” name=”grade” class=”form-control” required><img src=”images/grade_5.png” alt=”no image”>&nbsp;
<input type=”radio” name=”grade” class=”form-control” required><img src=”images/grade_6.png” alt=”no image”>&nbsp;
<input type=”radio” name=”grade” class=”form-control” required><img src=”images/grade_7.png” alt=”no image”>

For example, if the user selects the third option and the price is 5000, then the user gets the mail that “The cost for the option you have selected is 5000.”

I am not been able to write the php code for this. Please help me. Also I want to send these images to the receiver in mail when the user submits the form. How can I do this?

Thanks.

Regards
Saxena

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@phpmillionNov 08.2017 — What's your current code? Or do you want us to write a complete script for you?
Copy linkTweet thisAlerts:
@ssaxenaauthorNov 09.2017 — What's your current code? Or do you want us to write a complete script for you?[/QUOTE]

As I said, I am totally new to php and have written the following php with the help of experts like you. I know that I will have to use value in radio button and that value will be called with the help of php. I don't know how to do that. Following is my code.

&#65279;<?php

/**

* Simple example script using PHPMailer with exceptions enabled

*
@package phpmailer

* @version $Id$

*
/

require 'class.phpmailer.php';

try {

$mail = new PHPMailer(true); //New instance, with exceptions enabled

$to = "[email protected]";

$mail->AddAddress($to);

$mail->From = $_POST['email'];

$mail->FromName = $_
POST['name'];

$mail->Subject = "Contact Form";

$body = "<table>

<tr>

<th colspan='2'>Contact Form</th>

</tr>

<tr>

<td style='font-weight:bold'>Full Name:</td>

<td>".$_POST['name']."</td>

</tr>

<tr>

<td style='font-weight:bold'>E-Mail:</td>

<td>".$_POST['email']."</td>

</tr>

<tr>

<td style='font-weight:bold'>Mobile:</td>

<td>".$_POST['mobile_number']."</td>

</tr>

<tr>

<td style='font-weight:bold'>Age:</td>

<td>".$_POST['age']."</td>

</tr>

<tr>

<td style='font-weight:bold'>City: </td>

<td>".$_POST['city']."</td>

</tr>

<tr>

<td style='font-weight:bold'>Select Method: </td>

<td>".$_POST['method']."</td>

</tr>

<tr>

<td style='font-weight:bold'>Grade of Baldness: </td>

<td>".$_POST['grade']."</td>

</tr>

<table>";

$body = preg_replace('//','', $body); //Strip backslashes

$mail->MsgHTML($body);

$mail->IsSMTP(); // tell the class to use SMTP

$mail->SMTPAuth = true; // enable SMTP authentication

$mail->Port = 25; // set the SMTP server port

//$mail->Host = "[email protected]"; // SMTP server

//$mail->Username = "[email protected]"; // SMTP server username

//$mail->Password = "password"; // SMTP server password

$mail->IsSendmail(); // tell the class to use Sendmail

$mail->AddReplyTo("[email protected]");

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->WordWrap = 80; // set word wrap


$mail->IsHTML(true); // send as HTML

$mail->Send();

echo 'Thank You. Your form has been submitted. Please check your mail for details.';

} catch (phpmailerException $e) {

echo $e->errorMessage();

}


?>
Copy linkTweet thisAlerts:
@phpmillionNov 09.2017 — In this case, you should assign a value property to each radio box. Change:

[code=php]<input type="radio" name="grade" class="form-control" required>[/code]

to:

[code=php]<input type="radio" name="grade" class="form-control" value="VALUE YOU WANT TO SEND TO CLIENT" required>[/code]

Once you do so, [COLOR=#3E3E3E][B]$_POST['grade'][/B] will contain that value.[/COLOR]
Copy linkTweet thisAlerts:
@ssaxenaauthorNov 09.2017 — In this case, you should assign a value property to each radio box. Change:

[code=php]<input type="radio" name="grade" class="form-control" required>[/code]

to:

[code=php]<input type="radio" name="grade" class="form-control" value="VALUE YOU WANT TO SEND TO CLIENT" required>[/code]

Once you do so, [COLOR=#3E3E3E][B]$_POST['grade'][/B] will contain that value.[/COLOR][/QUOTE]


Thanks.

One of the experts has helped me with the following code:

$mail->Subject = "Contact Form";

$from = "[email protected]";

$to = isset($_POST['email']) ? $_POST['email'] : false;

// We would normally do a check here to see a) the address was provided and b) it is valid

// and if either of these fails abort the process. I will leave this to you to fill in as required

// You should send a copy to yourself so you know what was sent

$mail->AddAddress($from);

// Add the recipient address

$mail->AddAddress($to);

$mail->From = $from;

$mail->FromName = 'Your name here';

// TO HERE

$grade = isset($_POST['grade']) ? $_POST['grade'] : false;

// don't continue if no valid input obtained

if (!$grade || $grade < 1 || $grade > 7) die();

// Prices by grade

// Starts from grade 2 - no grade 0 or 1 so zero values

$prices = [0,0,200,300,400,500,600,700];

ob_start();

require_once('email_handler.email.php');

$body = ob_get_clean();

?>

The message that would be sent is as follows

<div style="color: red; border: 1px solid red; padding: 15px">

<em>

<?php echo $body;?>

</em>

</div>

But what is happening is that I am receiving the form but the user is not receiving any mail informing him the cost of the radio selection. Please tell me what wrong I am doing here.

Saxena
Copy linkTweet thisAlerts:
@StanliwiseNov 10.2017 — Try it with your email and after sending the mail, check wether the mail is been sent to spam folder.

If you are not a trusted agent, Google or YahooMail will put the mail into a spam folder.
Copy linkTweet thisAlerts:
@ssaxenaauthorNov 11.2017 — Try it with your email and after sending the mail, check wether the mail is been sent to spam folder.

If you are not a trusted agent, Google or YahooMail will put the mail into a spam folder.[/QUOTE]


Thanks everybody. My problem is solved.

Saxena
×

Success!

Help @ssaxena spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...