Following is my HTML Select field which gets all the emails from my database. Now I'm trying to send single or multiple emails with php. But It doesn't send any emails. Can you tell me what is wrong with my code ?
Html Code:
<tr>
<td valign="top">To</td>
<td>
<select multiple="multiple" size="7" name="to[]">
<?php
$getemail = mysql_query("SELECT email FROM clients");
while($res = mysql_fetch_array($getemail)){
$email = inputvalid($res['email']);
echo "<option value='$email'>$email</option>";
}
?>s
</select>
</td>
</tr>
Php Code:
foreach($to as $total){
$total;
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$mail = mail($total, $subject, $msg, $headers);
}
Update-Full Code:
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" />
<table width="400" border="0" cellspacing="10" cellpadding="0" style="float:left;
position:relative;">
<tr>
<td>Subject</td>
<td><input type="text" name="subject" value="<?php if(isset($_POST['subject'])) echo
$_POST['subject']; ?>" class="tr"/></td>
</tr>
<tr>
<td valign="top">Message</td>
<td><textarea name="msg" class="textarea_email"><?php if(isset($_POST['msg'])) echo
$_POST['msg']; ?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Send Message" class=" submit" name="Submit"/></td>
</tr>
</table>
<table style="float:left; position:relative; border:0px #000 solid;" width="400" border="0"
cellspacing="10" cellpadding="0">
<tr>
<td valign="top">To</td>
<td>
<select multiple="multiple" size="7" name="to[]">
<?php
$getemail = mysql_query("SELECT email FROM clients") or die(mysql_error());;
while($res = mysql_fetch_array($getemail)){
$email = inputvalid($res['email']);
echo "<option value='$email'>$email</option>";
}
?>s
</select>
</td>
</tr>
</table>
</form>
Php code:
if(isset($_POST['Submit']) && $_POST['Submit'] == "Send Message")
{
$subject = inputvalid($_POST['subject']);
$msg = inputvalid($_POST['msg']);
$to = $_POST['to'];
if(isset($subject) && isset($msg) && isset($to)){
if(empty($subject) && empty($msg) && empty($to))
$err[] = "All filed require";
}
else{
if(empty($to))
$err[] = "Please select email address";
if(empty($subject))
$err[] = "Subject require";
if(empty($msg))
$err[] = "Message require";
}
if(!empty($err))
{
echo "<div class='error'>";
foreach($err as $er)
{
echo "<font color=red>$er.</font>
<br/>";
}
echo "</div>";
echo "<br/>";
}
else{
foreach($to as $total){
echo $total;
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$mail = mail($total, $subject, $msg,
$headers);
}
if($mail)
echo "<font color=green>Successfully sent your message. We will be get in
touch with you. Thank You.</font/><br/><br/>";
header("Refresh:10; url=email.php");
}
}
You can send multiple emails for one mail function.
Only pass email address with comma separated.
like "test#gmail.com,test1#gmail.com"
first make sure that you query is correct.
Change the following line:
$getemail = mysql_query("SELECT email FROM clients");
to
$getemail = mysql_query("SELECT email FROM clients") or die(mysql_error());
Change the following line:
$total;
to
echo $total . '<BR />';
Save and refresh the page
What is your output?
Do you get an errormessage?
Do you see emailadresses?
edit:
change the following line
$mail = mail($total, $subject, $msg, $headers);
to
if (!mail($total, $subject, $msg, $headers);) {
echo 'This is not working';
}
What is your result?
Check your apache-configs! I had the same problem on my local machine. as soon as i uploaded it on a fully configured Webserver, the code started to work! Maybe this solves your problem, too
Some time mail() function may not work so you should go with PHPMailer, for more details to use this, you can go through a good documentation :
Send mail using PHPMailer
Related
i have created a form and it doesnt send out emails. I contacted my host and he said I need SMTP authentication. Form needs to send reservation info.
Here is my reservation.php file:
<script>
/////////////////// RESERVATION FORM //////////////////////
$("#ajax-contact-form").submit(function(){
var str = $(this).serialize();
document.getElementById('submit').disabled=true;
document.getElementById('submit').value='PLEASE WAIT';
$.ajax({
type: "POST",
url: "apartments_reservation_send.php",
data: str,
success: function(msg){
$("#note").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
result = '<div class="notification_ok">Thank you!<br />Your request is successfully sent!</div>';
$("#fields").hide();
}
else
{
document.getElementById('submit').disabled=false;
document.getElementById('submit').value='Send request';
result = msg;
autoReinitialise: true;
}
$(this).html(result);
});
}
});
return false;
});
</script>
<form id="ajax-contact-form" action="javascript:alert('success!');">
<table width="100%" cellpadding="3" cellspacing="3">
<tr>
<td width="50%" align="right" style="text-align: right;">
Arrival Date<span class="REQ">*</span> → <input id="arrivalDate" name="arrivalDate" size="30" type="text" class="date-pick" />
</td>
<td width="50%" align="left" style="text-align: left;">
<input id="departureDate" name="departureDate" size="30" type="text" class="date-pick" />
← <span class="REQ">*</span>Departure Date
</td>
</tr>
<tr>
<td width="50%" align="right" style="text-align: right;">
Adults<span class="REQ">*</span> →
<select id="Adults" name="Adults">
<option value=""></option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
<td width="50%" align="left" style="text-align: left;">
<select id="Children" name="Children">
<option value=""></option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
← <span class="REQ">*</span>Children
</td>
</tr>
</table>
<table width="100%" cellpadding="3" cellspacing="3">
<tr>
<td width="25%" align="right" valign="middle" style="text-align: right;">Name<span class="REQ">*</span> :</td>
<td width="75%" align="left" style="text-align: left;">
<input type="text" id="name" name="name" value="" size="86" />
</td>
</tr>
<tr>
<td align="right" valign="middle" style="text-align: right;">E-mail<span class="REQ">*</span> :</td>
<td align="left" style="text-align: left;">
<input type="text" id="email" name="email" value="" size="86" />
</td>
</tr>
<tr>
<td align="right" valign="middle" style="text-align: right;">Phone<span class="REQ">*</span> :</td>
<td align="left" style="text-align: left;">
<input type="text" id="phone" name="phone" value="" size="86" />
</td>
</tr>
<tr>
<td align="right" style="text-align: right;">Message :</td>
<td align="left" valign="top" style="text-align: left;">
<textarea id="message" name="message" rows="5" cols="87"></textarea>
</td>
</tr>
<tr>
<td width="100%" align="center" style="text-align: center;" colspan="2">
<input class="button" type="submit" name="submit" id="submit" value="Send request" />
</td>
</tr>
</table>
</form>
and here is my reservarion_send.php:
<?php
$TO_EMAIL = "info#thebunchofgrapesinn.com";
$FROM_EMAIL = "info#thebunchofgrapesinn.com";
$FROM_NAME = "thebunchofgrapes.com";
$SUBJECT = "The Bunch Og Grapes - Apartment Reservation";
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
include 'functions.php';
$ARIVAL_DATE = trim($_POST['arrivalDate']);
$DEPARTURE_DATE = trim($_POST['departureDate']);
$ADULTS = trim($_POST['Adults']);
$CHILDREN = trim($_POST['Children']);
$EMAIL = trim($_POST['email']);
$PHONE = trim($_POST['phone']);
$NAME = stripslashes($_POST['name']);
$MESSAGE = stripslashes($_POST['message']);
$ERROR = '';
if(!$ARIVAL_DATE)
{
$ERROR .= 'Please enter Arrival Date<br />';
}
if(!$DEPARTURE_DATE)
{
$ERROR .= 'Please enter Departure Date<br />';
}
//if(!$ADULTS)
//{
//$ERROR .= 'Please pick number of Adults<br />';
//}
//if(!$CHILDREN)
//{
//$ERROR .= 'Please pick number of Children<br />';
//}
if(!$NAME)
{
$ERROR .= 'Please enter Your Name.<br />';
}
if(!$EMAIL)
{
$ERROR .= 'Please enter Email address.<br />';
}
if($EMAIL && !ValidateEmail($EMAIL))
{
$ERROR .= 'Please enter valid Email address.<br />';
}
if(!$PHONE)
{
$ERROR .= 'Please enter You Phone Number.<br />';
}
//if(!$MESSAGE || strlen($MESSAGE) < 15) {
//$ERROR .= "Molimo unesite poruku. <br />Poruka mora imati najmanje 15 karaktera.<br />";
//}
$FULL_MESSAGE = "ARIVAL DATE = $ARIVAL_DATE\nDEPARTURE DATE = $DEPARTURE_DATE\nADULTS = $ADULTS\nCHILDREN = $CHILDREN\nNAME = $NAME\nEMAIL = $EMAIL\nPHONE = $PHONE\nMESSAGE = $MESSAGE";
if(!$ERROR)
{
$mail = mail($TO_EMAIL, $SUBJECT, $FULL_MESSAGE,
"From: ".$FROM_NAME." <".$FROM_EMAIL.">\r\n"
."Reply-To: ".$FROM_EMAIL."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail) {
echo 'OK';
}
}
else {
echo '<div class="notification_error">'.$ERROR.'</div>';
}
}
?>
and here is the link of the webpage http://thebunchofgrapesinn.com/apartments_reservation
I am not sure how to add SMTP authentication and what is wrong here, can someone help?
The behavior of php's mail() function varies depending on the server OS. Windows doesn't have a built in non-SMTP option like Unix-based servers. mail() is also limited in general without some advanced knowledge of working with headers.
If it's not inappropriate here to recommend a tool for the job, PHPMailer is a convenient enough goto solution for sending email from php. If your server is Unix/Linux based, you can leave out $mail->isSMTP() and the related options and PHPMailer will use the server's sendmail implementation. If you are on Windows or have SMTP details handy, PHPMailer makes that simple enough.
You can use PHPMailer and Swiftmailer, these are common libraries for sending smtp mails. PhpMailer is a little simpler than swift and documentations is easy to understand.
But you can write your own smtp client for this but first you need to learn how to make a socket connection in php. PHPMailers smtp class is a good hint to create one.
If you have administrator rights for your server, you can connect your sendmail mail function to a smtp server, here is a documantation how to. Php has a mail configuration option for smtp though i never used it before.
By the way, php.ini has a sendmail_path option to read your STDOUT data and send mail. If you want, you can change this sendmail_path param with a bash, php, or a python script. But i do not recommend it.
Most of the host have SMTP already configured.In order to debug test mail() function seperately.Just make a file like 'mail.php' and put the below code in to it :
<?php
$email ="PUT EMAIL ID OF USER HERE";
$subject ="Reservation Info";
$headers = "From: " . '<thebunchofgrapesinn.com/>' . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html>
<body>
<p>Its Just A Testing Mail</p>
</body>
</html>";
if(mail($email,$subject, $message, $headers)){
echo 'mail sent';
}
?>
Check weather it works or not.Also prefer to use phpmailer.Here is the link for downloding PHPmailer class it also has example.
i had Encrypted my password in register.php
<?php
// Set error message as blank upon arrival to page
$errorMsg = "";
// First we check to see if the form has been submitted
if (isset($_POST['username'])){
//Connect to the database through our include
include_once "connect_to_mysql.php";
// Filter the posted variables
$username = ereg_replace("[^A-Za-z0-9]", "", $_POST['username']); // filter everything but numbers and letters
$country = ereg_replace("[^A-Z a-z0-9]", "", $_POST['country']); // filter everything but spaces, numbers, and letters
$state = ereg_replace("[^A-Z a-z0-9]", "", $_POST['state']); // filter everything but spaces, numbers, and letters
$city = ereg_replace("[^A-Z a-z0-9]", "", $_POST['city']); // filter everything but spaces, numbers, and letters
$accounttype = ereg_replace("[^a-z]", "", $_POST['accounttype']); // filter everything but lowercase letters
$email = stripslashes($_POST['email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
// Check to see if the user filled all fields with
// the "Required"(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$username) || (!$country) || (!$state) || (!$city) || (!$accounttype) || (!$email) || (!$password)){
$errorMsg = "You did not submit the following required information!<br /><br />";
if(!$username){
$errorMsg .= "--- User Name";
} else if(!$country){
$errorMsg .= "--- Country";
} else if(!$state){
$errorMsg .= "--- State";
} else if(!$city){
$errorMsg .= "--- City";
} else if(!$accounttype){
$errorMsg .= "--- Account Type";
} else if(!$email){
$errorMsg .= "--- Email Address";
} else if(!$password){
$errorMsg .= "--- Password";
}
} else {
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT id FROM members WHERE username='$username' LIMIT 1");
$sql_email_check = mysql_query("SELECT id FROM members WHERE email='$email' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check);
$email_check = mysql_num_rows($sql_email_check);
if ($username_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else if ($email_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
} else {
// Add MD5 Hash to the password variable
$hashedPass = md5($password);
// Add user info into the database table, claim your fields then values
$sql = mysql_query("INSERT INTO members (username, country, state, city, accounttype, email, password, signupdate)
VALUES('$username','$country','$state','$city','$accounttype','$email','$hashedPass', now())") or die (mysql_error());
// Get the inserted ID here to use in the activation email
$id = mysql_insert_id();
// Create directory(folder) to hold each user files(pics, MP3s, etc.)
mkdir("memberFiles/$id", 0755);
// Start assembly of Email Member the activation link
$to = "$email";
// Change this to your site admin email
$from = "geetha.victor#tryteksolutions.co.in";
$subject = "Complete your registration";
//Begin HTML Email Message where you need to change the activation URL inside
$message = '<html>
<body bgcolor="#FFFFFF">
Hi ' . $username . ',
<br /><br />
You must complete this step to activate your account with us.
<br /><br />
Please click here to activate now >>
<a href="http://www.trytek.tryteksolutions.co.in/activation.php?id=' . $id . '">
ACTIVATE NOW</a>
<br /><br />
Your Login Data is as follows:
<br /><br />
E-mail Address: ' . $email . ' <br />
Password: ' . $password . '
<br /><br />
Thanks!
</body>
</html>';
// end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
// Finally send the activation email to the member
mail($to, $subject, $message, $headers);
// Then print a message to the browser for the joiner
print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />
We just sent an Activation link to: $email<br /><br />
<strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
Link inside the message. After email activation you can log in.";
exit(); // Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks
} // Close else after missing vars check
} //Close if $_POST
?>
<!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=iso-8859-1" />
<title>Member Registration</title>
</head>
<body>
<table width="600" align="center" cellpadding="4">
<tr>
<td width="7%">REGISTER AS A MEMBER HERE </td>
</tr>
</table>
<table width="600" align="center" cellpadding="5">
<form action="join_form.php" method="post" enctype="multipart/form-data">
<tr>
<td colspan="2"><font color="#FF0000"><?php echo "$errorMsg"; ?></font></td>
</tr>
<tr>
<td width="163"><div align="right">User Name:</div></td>
<td width="409"><input name="username" type="text" value="<?php echo "$username"; ?>" /></td>
</tr>
<tr>
<td><div align="right">Country:</div></td>
<td><select name="country">
<option value="<?php echo "$country"; ?>"><?php echo "$country"; ?></option>
<option value="Australia">Australia</option>
<option value="Canada">Canada</option>
<option value="Mexico">Mexico</option>
<option value="United Kingdom">United Kingdom</option>
<option value="United States">United States</option>
<option value="Zimbabwe">Zimbabwe</option>
</select></td>
</tr>
<tr>
<td><div align="right">State: </div></td>
<td><input name="state" type="text" value="<?php echo "$state"; ?>" /></td>
</tr>
<tr>
<td><div align="right">City: </div></td>
<td>
<input name="city" type="text" value="<?php echo "$city"; ?>" />
</td>
</tr>
<tr>
<td><div align="right">Account Type: </div></td>
<td><select name="accounttype">
<option value="<?php echo "$accounttype"; ?>"><?php echo "$accounttype"; ?></option>
<option value="a">Normal User</option>
<option value="b">Expert User</option>
<option value="c">Super User</option>
</select></td>
</tr>
<tr>
<td><div align="right">Email: </div></td>
<td><input name="email" type="text" value="<?php echo "$email"; ?>" /></td>
</tr>
<tr>
<td><div align="right"> Password: </div></td>
<td><input name="password" type="password" value="<?php echo "$password"; ?>" />
<font size="-2" color="#006600">(letters or numbers only, no spaces no symbols)</font></td>
</tr>
<tr>
<td><div align="right"> Captcha: </div></td>
<td>Add Captcha Here for security</td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input type="submit" name="Submit" value="Submit Form" /></td>
</tr>
</form>
</table>
</body>
</html>
This is my forgot password script in which i have a problem in sending encrypt password in mail. how to decrypt a password and send decrypted password in mail.
<?php session_start();
include "connect_to_mysql.php"; //connects to the database
if (isset($_POST['email'])){
$email = $_POST['email'];
$query="select * from members where email='$email'";
$result = mysql_query($query);
$count=mysql_num_rows($result);
// If the count is equal to one, we will send message other wise display an error message.
if($count==1)
{
$rows=mysql_fetch_array($result);
$password = $rows['password'];//FETCHING PASS
//echo "your pass is ::".($pass)."";
$to = $rows['email'];
//echo "your email is ::".$email;
//Details for sending E-mail
$from = "geetha.victor#tryteksolutions.co.in";
$url = "http://abc.co.in/";
$body = "TrytekSolutions password recovery <br />
---------------------------------------------------------- <br />
Url : $url;<br />
email Details is : $to;<br />
Here is your password : $password;<br /> <br />
Sincerely, <br />
TryTekSolutions";
$from = "abc#tryteksolutions.co.in";
$subject = "Tryteksolutions Password recovered";
$headers1 = "From: $from\n";
$headers1 .= "Content-type: text/html;charset=iso-8859-1\r\n";
$headers1 .= "X-Priority: 1\r\n";
$headers1 .= "X-MSMail-Priority: High\r\n";
$headers1 .= "X-Mailer: Just My Server\r\n";
$sentmail = mail ( $to, $subject, $body, $headers1 );
} else {
if ($_POST ['email'] != "") {
echo "<span style='color: #ff0000;'> Not found your email in our database</span>";
}
}
//If the message is sent successfully, display sucess message otherwise display an error message.
if($sentmail==1)
{
echo "<span style='color: #ff0000;'> Your Password Has Been Sent To Your Email Address.</span>";
}
else
{
if($_POST['email']!="")
echo "<span style='color: #ff0000;'> Cannot send password to your e-mail address.Problem with sending mail...</span>";
}
}
?>
help me friends how to decrypt a password and send mail.
Don't. You should never be able to convert the stored password data into an actual password. They should be hashed, not encrypted.
MD5 is a hashing algorithm, but a very weak one that is entirely unsuitable for protecting passwords with today. You need to take better care of your users' passwords.
If someone loses their password, then generate a time-limited random reset token and email it to the user.
When they enter that token (usually by following a link in the email with the token embedded in it) allow them to choose a new password.
<html>
<head>
<title>Max Design contact page</title>
<link href="mdstyle1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<?php
$required = array("firstName" => "First Name",
"surname" => "Surname",
"email" => "Email Address",
"telephone" => "Telephone");
foreach($required as $field => $label) {
if (!$_POST[$field]) {
$warnings[$field] = "*";
}
}
if ($_POST["firstName"] &&
!ereg("[a-zA-Z]", $_POST["firstName"]))
$warnings["firstName"] = "Please check First Name for errors";
if ($_POST["surname"] &&
!ereg("[a-zA-Z]", $_POST["surname"]))
$warnings["surname"] = "Please check Surname for errors";
if ($_POST["email"] &&
!ereg("^[^#]+#([a-z\-]+\.)+[a-z]{2,4}$", $_POST["email"]))
$warnings["email"] = "Please check email for errors";
if ($_POST["telephone"] &&
!ereg("[0-9]", $_POST["telephone"]))
$warnings["telephone"] = "Please check Telephone for errors";
if (count($warnings) > 0) {
// sets the description of the sections of the form and must have an entry for each form element
$description = array();
$description{"firstName"} = "First Name";
$description{"surname"} = "Surname";
$description{"telephone"} = "Telephone Number";
$description{"email"} = "Email Address";
?>
<div class="main-paragraph">
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<br />
<div class="warnings"> * Please fill in these boxes </div>
<br />
<br />
<TABLE BORDER=0>
<TR>
<TD><label>First Name</label>
</TD><TD><INPUT TYPE=TEXT SIZE=30 NAME="firstName"
VALUE="<?php echo $_POST["firstName"];?>"></TD>
<TD><div class="warnings"><?php echo $warnings["firstName"];?></div></TD>
</TR>
<TR>
<TD><label>Surname</label>
</TD><TD><INPUT TYPE=TEXT SIZE=30 NAME="surname"
VALUE="<?php echo $_POST["surname"];?>"></TD>
<TD><div class="warnings"><?php echo $warnings["surname"];?></div></TD>
</TR>
<TR>
<TD><label>Email Address</label>
</TD>
<TD><INPUT TYPE=TEXT SIZE=30 NAME="email"
VALUE="<?php echo $_POST["email"];?>"></TD>
<TD><div class="warnings"><?php echo $warnings["email"];?></div></TD>
</TR>
<TR>
<TD><label>Telephone</label>
</TD>
<TD><INPUT TYPE=TEXT SIZE=15 NAME="telephone"
VALUE="<?php echo $_POST["telephone"];?>"></TD>
<TD><div class="warnings"><?php echo $warnings["telephone"];?></div></TD>
</TR>
</TABLE>
<br />
<INPUT TYPE=SUBMIT VALUE="Send Enquiry">
</FORM>
</div> <!-- end of main paragraph -->
<?php
}
else { // start of send section
//stuff that goes to the enquirer
$clients_email = "From: sales#rmrc.co.uk";
$headers2 = "From: simon#maxdesign.org.uk";
$subject2 = "Thank you for contacting MAX Design";
$autoreply = "Thank you for contacting MAX Design. We will get back to you as soon as possible,
\n usualy within 48 hours. If you have any more questions,
\n please consult our website at www.maxdesign.org.uk/index";
//prints out each field's title and contents in turn each on new line
$body = "A quote request from the website:\n\n";
foreach($_POST as $description => $value) {
$body .= sprintf("%s = %s\n", $description, $value);
}
mail($email, $subject2, $autoreply, $headers2);
mail("sim.on#hotmail.co.uk", "MAX Design website enquiry", $body, $email);
header( "Location: http://www.maxdesign.org.uk/thank-you-for-quote-max-design.html" );
} //end of send section
?>
</div><!--end of container/wrapper div -->
</body>
</html>
I am trying to send a fairly crudely formatted email (I am trying to get the email formatted a little bit using the $description variable but that isn't working either) from the clients website but the script won't send it to the clients email using the $email string so am having no luck. Have been at this for days now so any help really appreciated.
Simon
You are sending a variable called $email to your mail() which is not at all defined in the code. That is why your mail is not being sent. See below
mail($email, $subject2, $autoreply, $headers2);
//^^^^^ Undefined variable
Solution : Set the $email to some email.
i'm new in php..i would like to sent contact form to my gmail account..
everything just going fine whrn i click the submit button,but my problem is this form not sending me the email..
this is my html code
<form action="kontact-sent" onSubmit="return validate_form(this)" method="post">
<table width="415" border="0" cellspacing="1" cellpadding="5" class="t1">
<tr>
<td align="left" valign="top" bgcolor="#efefef">First name:<br /><input name="FirstName" type="text" id="FirstName" style="width:300px;" /></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef">Email address<br /><input type="text" name="EmailAddress" id="EmailAddress" style="width:300px;" />
<input name="Email_Confirmation" class="Email_Confirmation2"/></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef">Message<br /><textarea name="Inquiry" id="Inquiry" style="width:300px; height:100px;"></textarea></td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#efefef"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
function validate_EmailAddress(field,alerttxt){
with (field)
{
apos=value.indexOf("#");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(FirstName,"Please enter your First Name.")==false)
{FirstName.focus();return false;}
if (validate_EmailAddress(EmailAddress,"Please enter a valid Email Address.")==false)
{EmailAddress.focus();return false;}
if (validate_Inquiry(Inquiry,"Please enter your Inquiry.")==false)
{Inquiry.focus();return false;}
}
}
this is my .php
<?php
// if the Email_Confirmation field is empty
if(isset($_POST['Email_Confirmation']) && $_POST['Email_Confirmation'] == ''){
// put your email address here scott.langley.ngfa#statefarm.com, slangleys#yahoo.com
$youremail = 'afiqrashid91#gmail.com';
// prepare a "pretty" version of the message
$body .= "Thank You for contacting us! We will get back with you soon.";
$body .= "\r\n";
$body .= "\r\n";
foreach ($_POST as $Field=>$Value) {
$body .= "$Field: $Value\r\n";
$body .= "\r\n";
}
$CCUser = $_POST['EmailAddress'];
// Use the submitters email if they supplied one
// (and it isn't trying to hack your form).
// Otherwise send from your email address.
if( $_POST['EmailAddress'] && !preg_match( "/[\r\n]/", $_POST['EmailAddress']) ) {
$headers = "From: $_POST[EmailAddress]";
} else {
$headers = "From: $youremail";
}
// finally, send the message
mail($youremail, 'Form request', $body, $headers, $CCUser );
}
// otherwise, let the spammer think that they got their message through
?>
Thank You for contacting us! We will get back with you soon.
i hope that anyone can help me..thanks in advance..
$headers = "From: $_POST[EmailAddress]";
Should be:
$headers = "From: $_POST['EmailAddress']";
Also, email messages shouldn't exceed 70 characters per line. You'll want to fix this by adding:
$body = wordwrap($body, 70);
I realise this question has been asked numerous times before but everyone's code is obviously different and I am quite new to php so just looking to see if someone can give me some help.
I have created a basic contact form for a site but for some reason the information is not being sent to my email address although I believe that the form is submitted?
my PHP code is:
<?php
session_start();
//$to_mail = "architects#palavin.com,t.lavin#palavin.com,12yorkcourt#gmail.com";
$to_mail = "danny#enhance.ie";
//$cc="paul#enhance.ie";
$mail_sent = 0;
if(isset($_POST['submit'])){
//echo "the form was submitted";
$error= array();
$name = trim(strip_tags($_POST['name']));
if($name == "")
$error['name'] = 1;
$email = trim(strip_tags($_POST['email']));
if($email == "")
$error['email'] = 1;
$phone = trim(strip_tags($_POST['phone']));
$address = trim(strip_tags($_POST['address']));
$description = trim(strip_tags($_POST['description']));
$str = trim(strip_tags($_POST['secu']));
if ( isset($_SESSION['code_']) && $_SESSION['code_'] == strtoupper($str)){} else {$error['secu'] = 1;}
if(empty($error)){
$headers = 'From: "Euro Insulation" <no-reply#euroinsulations.ie>'."\r\n";
//$headers .= 'CC: "'.$cc.'" <'.$cc.'>'."\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "";
$subject = "New contact message";
$message = "New Contact message, received from: <br /> \n ";
$message .= "<b>Name</b> ".$name."<br /> \n";
$message .= "<b>Email</b> ".$email."<br /> \n";
$message .= "<b>Phone</b> ".$phone."<br /> \n";
$message .= "<b>Address</b> ".$address."<br /> \n";
$message .= "<b>Description</b> ".$description."<br /> \n";
if(#mail($to_mail,$subject,$message,$headers ))
{
echo "mail sent";
$mail_sent = 1;
}
else echo "mail not sent";
}
}
?>
my html form looks like this:
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="65%" valign="top"><p class="header"><br>
Contact US <br>
</p>
<?php if($mail_sent==1){
print "Thank you for your message.";
} else { ?>
<form class="email_sub" method="post" >
<table width="77%" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td><label for="name" class="formtext" <?php if($error['name']==1) echo "style='color:red;'" ?> >Name:</label></td>
<td><input type="text" name="name" id="text" <?php if($name) echo "value='".$name."'" ?> /></td>
</tr>
<tr>
<td><label for="phone" class="formtext">Number:</label></td>
<td><input type="text" name="phone" id="phone"/><tr>
<br />
<tr>
<td><label for="email" class="textarea" <?php if($error['email']==1) echo "style='color:red;'" ?>>Email:</label></td>
<td><input type="text" name="email" id="email" <?php if($email) echo "value='".$email."'" ?> /></td>
</tr>
<tr>
<td><br /></td>
</tr>
<tr><td><label for="address" class="textarea">Address/Location of project:</label></td>
<td><textarea rows="3" cols="20" name="address" id="address" style="width: 400px;"><?php if($address!="") echo $address ?></textarea></td>
</tr>
<tr>
<td><br /></td>
</tr>
<br />
<tr>
<td><label for="description" class="fixedwidth">Enquiry</label></td>
<td><textarea rows="3" cols="20" name="description" id="description" style="width: 400px;"><?php if($description!="") echo $description; ?></textarea></td>
<tr>
<td><br /></td>
</tr>
<!-- form -->
<tr>
<td><label> </label></td>
<td><input type="submit" value="Submit" name="submit" /></td>
</tr>
</table>
</form>
<?php } ?>
Am i missing something obvious here?? Any help will really be appreciated thanks!
You have used sessions which is not required here, you can also use flag variable instead of arrays in this simple form, use this updated code.
<?php
//$to_mail = "architects#palavin.com,t.lavin#palavin.com,12yorkcourt#gmail.com";
$to_mail = "danny#enhance.ie";
//$cc="paul#enhance.ie";
$mail_sent = 0;
if(isset($_POST['submit'])){
//echo "the form was submitted";
$name = trim(strip_tags($_POST['name']));
if($name == "")
$error = true;
$email = trim(strip_tags($_POST['email']));
if($email == "")
$error = true;
$phone = trim(strip_tags($_POST['phone']));
$address = trim(strip_tags($_POST['address']));
$description = trim(strip_tags($_POST['description']));
if($error != true){
$headers = 'From: "Euro Insulation" <no-reply#euroinsulations.ie>'."\r\n";
//$headers .= 'CC: "'.$cc.'" <'.$cc.'>'."\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "";
$subject = "New contact message";
$message = "New Contact message, received from: <br /> \n ";
$message .= "<b>Name</b> ".$name."<br /> \n";
$message .= "<b>Email</b> ".$email."<br /> \n";
$message .= "<b>Phone</b> ".$phone."<br /> \n";
$message .= "<b>Address</b> ".$address."<br /> \n";
$message .= "<b>Description</b> ".$description."<br /> \n";
if(#mail($to_mail,$subject,$message,$headers))
{
echo "mail sent";
$mail_sent = 1;
}
else echo "mail not sent";
} else {
echo 'validation error';
}
}
?>
You have also missed out the else statement for your form validation test so no errors getting displayed when you submit form.
Remove the at sign from mail function and see what errors your get. #mail suppresses errors from being displayed.
Comment out the following line: if ( isset($SESSION['code']) && $SESSION['code'] == strtoupper($str)){} else {$error['secu'] = 1;}
You should be able to reach the mail function.