Jump to content

Sending email one copy if check box is checked


ksumanth

Recommended Posts

Hello friends,

 

I have an enquiry form to send an email. In that i used one option checkbox. Normally while sending mail it sending. If check box is checked i need to send one to copy to particular sending mail id and fixed mail id here is my code.

 

Can any one fix this,

 

<form id="frm" class="iformlog" name="frm" method="post" action="contactprocess.php">

<table width="100%" border="0" cellspacing="0" cellpadding="5">

<tr>

<td>

 

<li style="height:20px;margin-bottom:10px;">

<label for="Last Name" style="margin-left:-10px;font-size:13px;">

Name<span style="color:#FF0000;">*</span></label>    

<input class="itext" name="name" placeholder="Enter Name" type=text required onchange="isAlphabet(this)" style="margin-top:10px;margin-left:30px;" value=""></li>

<li style="height:20px;">

<label for="Last Name" style="margin-left:-10px;font-size:13px;">

Email Id<span style="color:#FF0000;">*</span></label>       

<input class="itext" name="email" placeholder="Enter Email" type=text required style=""

onchange="echecko(this)" value=""></li>

 

<li style="height:20px;">

<label for="Last Name" style="margin-left:-10px;font-size:13px;">

Subject<span style="color:#FF0000;">*</span></label>       

<input class="itext" name="subject" placeholder="Enter Subject" type=text required style=""

onchange="echecko(this)" value=""></li>

 

<div style="border:1p solid black;font-family:Tahoma,Arial,Sans-serif;font-size:14px; width:auto; height:auto;margin-left:-5px;">Message <span style="color:#FF0000;">*</span></div>

<li style="border:width:200px;margin-left:80px;margin-top:-28px;">

<textarea name="Message" placeholder="Enter Message" required class="itextarea"></textarea></li>

 

</td>

 

 

</tr>

<tr>

 

<td align="right">                   

<input type="checkbox" name="sendcopy" value="Yes" /> Send One Copy to my mail </td>

</tr>

<tr>

 

<td colspan="2">

<li style="height:20px;margin-left:100px;">

 

<input class="ibutton" type="submit" name="submit" id="submit" value="Submit" /> 

<input class="ibutton" type="reset" name="reset" value="Reset" />

</li>

 

</td></tr>

 

</td>

</tr>

</table>

</form>

 

 

Here process page code

 

<?

echo $name=$_POST['name'];

echo $email=$_POST['email'];

echo $subject=$_POST['subject'];

echo $message=$_POST['Message'];

 

?>

<?php

if(isset($_POST['submit']))

{

function send_email ($to_email, $from_email, $from_name, $subject, $msg) {

//split up to email array, if given

if (is_array($to_email)) {

$to_email_string = implode(', ', $to_email);

}

else {

$to_email_string = $to_email;

}

 

//Assemble headers

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= "From: $from_name <$from_email>" . "\r\n";

 

 

//send via PHP's mail() function

$mailsent=mail($to_email_string, $subject, $msg, $headers);

if($mailsent)

{

echo "<script>alert('Mail sent')</script>";

?>

<script>

window.location = 'index.php';

</script>

<?

}

else

{

echo "<script>alert('Not sent')</script>";

}

}

 

//$address=$_POST['address'];

 

$from = $name;

 

$subject = 'Enquiry Form ';

$message ="<html> <body >

<p><label>Contact Details</label></p>

<p><label><b>Name:</b></label>$name</p>

 

<p><label><b>Email:</b></label>$email</p>

<p><label><b>Your Questions:</b></label><br/>

$message

</p></body></html>";

send_email("[email protected]",$email , "ADC Enquiry", $subject, $message);

?>

 

 

<?

 

if(isset($_POST["sendcopy"]) && $_POST["sendcopy"]=="Yes")

{

echo $name=$_POST['name'];

echo $email=$_POST['email'];

echo $subject=$_POST['subject'];

echo $message=$_POST['Message'];

 

 

function send_email ($to_email, $from_email, $from_name, $subject, $msg) {

//split up to email array, if given

if (is_array($to_email)) {

$to_email_string = implode(', ', $to_email);

}

else {

$to_email_string = $to_email;

}

 

//Assemble headers

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= "From: $from_name <$from_email>" . "\r\n";

 

 

//send via PHP's mail() function

$mailsent=mail($to_email_string, $subject, $msg, $headers);

if($mailsent)

{

echo "<script>alert('Mail sent')</script>";

?>

<script>

window.location = 'index.php';

</script>

<?

}

else

{

echo "<script>alert('Not sent')</script>";

}

}

 

//$address=$_POST['address'];

 

$from = $name;

 

$subject = 'Enquiry Form ';

$message ="<html> <body >

<p><label>Contact Details</label></p>

<p><label><b>Name:</b></label>$name</p>

 

<p><label><b>Email:</b></label>$email</p>

<p><label><b>Your Questions:</b></label><br/>

$message

</p></body></html>";

send_email("[email protected]",$email,$email, "ADC puppy", $subject, $message);

 

}

}

?>

First of all: Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read.

 

For your question: Just check if the checkbox index is set in the $_POST array, and then add a BCC: or CC: header to the e-mail. Depending upon if you want the e-mail address be visible to the recipient of the original mail, or not.

This is my form

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

<body>

<form id="frm" name="frm" method="post" action="contactprocess.php">

<table width="100%" border="0" cellspacing="0" cellpadding="5">

<tr>

 

<td>Name</td>

<td><input name="name" placeholder="Enter Name" type=text required value=""></td>

</tr>

<tr>

<td>Email Id</td>

<td><input name="email" placeholder="Enter Email" type=text required value=""></td></tr>

<tr>

<td>Subject</td>

<td><input name="subject" placeholder="Enter Subject" type=text required value=""></td> </tr>

<tr>

<td>Message</td>

<td><textarea name="Message" placeholder="Enter Message" required class="itextarea"></textarea></td>

</tr>

<tr>

<td>

<input type="checkbox" name="sendcopy" value="Yes" /> Send One Copy to my mail </td>

</tr>

<tr>

<td colspan="2">

<input type="submit" name="submit" id="submit" value="Submit" />

<input type="reset" name="reset" value="Reset" />

</td>

</tr>

</table>

</form>

</body>

</html>

This is process page

<?

echo $name=$_POST['name'];

echo $email=$_POST['email'];

echo $subject=$_POST['subject'];

echo $message=$_POST['Message'];

 

?>

<?php

if(isset($_POST['submit']))

{

function send_email ($to_email, $from_email, $from_name, $subject, $msg) {

//split up to email array, if given

if (is_array($to_email)) {

$to_email_string = implode(', ', $to_email);

}

else {

$to_email_string = $to_email;

}

 

//Assemble headers

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= "From: $from_name <$from_email>" . "\r\n";

 

 

//send via PHP's mail() function

$mailsent=mail($to_email_string, $subject, $msg, $headers);

if($mailsent)

{

echo "<script>alert('Mail sent')</script>";

?>

<script>

window.location = 'index.php';

</script>

<?

}

else

{

echo "<script>alert('Not sent')</script>";

}

}

 

//$address=$_POST['address'];

 

$from = $name;

 

$subject = 'Enquiry Form ';

$message ="<html> <body >

<p><label>Contact Details</label></p>

<p><label><b>Name:</b></label>$name</p>

 

<p><label><b>Email:</b></label>$email</p>

<p><label><b>Your Questions:</b></label><br/>

$message

</p></body></html>";

send_email("[email protected]",$email , " Enquiry", $subject, $message);

}

?>

 

This is normal sending mail i need while i click check box it should send one copy to [email protected] and one copy to from_mail(who is sending enquiry form)

 

Thanks

Sumanth

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.