I have a problem with my PHP Mail. It stops working from time to time without me even touching the code. I have a script which checks if required forms are empty. This script works. But if I fill in all the required fields I should get a text which says "Your mail was successfully sent" but I don't. But if I edit my code by just moving a bit of text some lines down and back to the original position again it works, for a while. It's often under the night it stops working. Can it be the server that is causing trouble or is it my code that I posted below?
<?php
if(isset($_POST['submit'])){
$namn = strip_tags($_POST['namn']);
$foretag = strip_tags($_POST['foretag']);
$adress = strip_tags($_POST['adress']);
$postnr = strip_tags($_POST['postnr']);
$ort = strip_tags($_POST['ort']);
$telefon = strip_tags($_POST['telefon']);
$epost = strip_tags($_POST['epost']);
$meddelande = strip_tags($_POST['meddelande']);
function check_required_fields($required_array){
$field_errors = array();
foreach($required_array as $fieldname){
if ((!isset($_POST[$fieldname])) || (empty($_POST[$fieldname]))){
if($_POST[$fieldname] != '0'){
$field_errors[] = $fieldname;
}
}
}
return $field_errors;
}
$errors = array();
$required_fields = array('namn', 'telefon', 'meddelande');
$errors = array_merge($errors, check_required_fields($required_fields));
if(empty($errors)){
$meddelande=nl2br($meddelande);
if(empty($foretag)){ $foretag='-'; }
if(empty($adress)){ $adress='-'; }
if(empty($postnr)){ $postnr='-'; }
if(empty($ort)){ $ort='-'; }
if(empty($epost)){ $epost='-'; }
$body =
"
Namn: <b>". $namn ."</b><br />
Företag: <b>". $foretag ."</b><br />
Adress: <b>". $adress ."</b><br />
Postnr: <b>". $postnr ."</b><br />
Ort: <b>". $ort ."</b><br />
Telefon: <b>". $telefon ."</b><br />
E-post: <b>". $epost ."</b><br /><br />
Meddelande: <b><br />". $meddelande
;
$headers = "From: $namn <webmaster#allflytt.com>\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "X-Mailer: PHP v".phpversion();
$success = mail('info#allflytt.com', 'Meddelande', $body, $headers);
}
}
?>
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<?php
if(!empty($errors)){
echo "<p class=\"field_error\">De rödmarkerade fälten måste fyllas i.</p>";
}
?>
<?php
if(empty($errors) && $success){
echo "<p class=\"p_success\">Tack för ditt meddelande! Vi kommer att besvara det inom kort.</p>";
}
?>
<p>
<label for="namn">
<?php if(!empty($errors)){if(in_array("namn", $errors)){echo "<span class=\"field_error\">";}}?>Namn: *<?php if(!empty($errors)){if(in_array("namn", $errors)){echo "</span>";}} ?>
</label><br />
<input type="text" name="namn" id="namn" class="text" tabindex="15" value="<?php if(!empty($errors)){ echo $namn; } ?>" />
<br />
<label for="foretag">Företag:</label><br />
<input type="text" name="foretag" id="foretag" class="text" tabindex="20" value="<?php if(!empty($errors)){ echo $foretag; }?>" />
<br />
<label for="adress">Adress:</label><br />
<input type="text" name="adress" id="adress" class="text" tabindex="30" value="<?php if(!empty($errors)){ echo $adress; } ?>" />
<br />
<label for="postnr">Postnummer:</label><br />
<input type="text" name="postnr" id="postnr" class="text_medium" tabindex="40" value="<?php if(!empty($errors)){ echo $postnr; } ?>" />
<br />
<label for="ort">Ort:</label><br />
<input type="text" name="ort" id="ort" class="text" tabindex="50" value="<?php if(!empty($errors)){ echo $ort; } ?>" />
<br />
<label for="telefon">
<?php if(!empty($errors)){if(in_array("telefon", $errors)){echo "<span class=\"field_error\">";}}?>Telefon: *<?php if(!empty($errors)){if(in_array("telefon", $errors)){echo "</span>";}} ?>
</label><br />
<input type="text" name="telefon" id="telefon" class="text" tabindex="60" value="<?php if(!empty($errors)){ echo $telefon; } ?>" />
<br />
<label for="epost">E-post:</label><br />
<input type="text" name="epost" id="epost" class="text" tabindex="70" value="<?php if(!empty($errors)){ echo $epost; } ?>" />
<br />
<label for="meddelande">
<?php if(!empty($errors)){if(in_array("meddelande", $errors)){echo "<span class=\"field_error\">";}}?>Meddelande: *<?php if(!empty($errors)){if(in_array("meddelande", $errors)){echo "</span>";}} ?>
</label><br />
<textarea name="meddelande" id="meddelande" class="textarea" tabindex="80"><?php if(!empty($errors)){ echo $meddelande; } ?></textarea>
<br />
<input type="submit" name="submit" value="Skicka" class="submit" />
</p>
</form>
could not find if anything wrong in your code.
check if APC cache is enabled in your server.
sometimes it creates problem in taking updated code.
if you are using SMTP server then mail() function may not work.
you can use PEARS for this.
I have experienced a similar problem. Turned out the browser, by error, sometimes double-posts your form; One time with content and another time without content.
If no content is submitted to your script, obviously there's nothing to act upon. There are a number of ways to check on this, but they way I discovered it was a desperate last resort measure where I sent emails to myself with each run of the script. And I showed that I often got two mails where the script had run only once.
It's worht trying :)
Problem solved. Changed to a new server host. No issues any more!
Related
I am trying to make a quote forum that sends the input to an email. I have PHP sending the email, displaying the subject and the senders email, but it doesn't display the main body of content in the email that is sent.. here is my code:
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<div class="quote_text">Send us some of your information and we will get back to you as soon as possible. Let's get this ball rolling.</div>
<br /><br />
<span class="important">* = required fields</span><br />
<form action="" method="POST" enctype="multipart/form-data">
<table width="814" height="310" border="0">
<tr>
<td width="419">
<input type="hidden" name="action" value="submit">
Your Name:<span class="important">*</span><input name="name" type="text" value="" size="30"/><br /><br />
Your Email:<span class="important">*</span><input name="email" type="text" value="" size="30" placeholder="example#example.com"/><br /><br />
Phone Number:<input name="phone" type="text" value="" size="10" maxlength="12" placeholder="(xxx)-xxx-xxxx" /><br /><br />
Company Name:<input name="company_name" type="text" value="" size="30"/><br /> <br />
</td>
<td width="385">
Address of Installation:<span class="important">*</span>
<input name="install_address" type="text" value="" size="30"/><br /><br />
City:<span class="important">*</span><input name="city" type="text" value="" size="30"/><br /><br />
State:<span class="important">*</span><input name="state" type="text" value="" size="30"/><br /><br />
Zip Code:<span class="important">*</span><input name="zip" type="text" value="" size="30"/><br /><br /><br /><br />
</td>
</tr>
<tr>
<td height="102">
Fence Type Description:<br /><textarea name="description" rows="6" cols="45"></textarea>
Number of Corners:<input name="corners" type="text" value="" size="30"/>
</td>
<td><br />
Linear Feet:<input name="linear" type="text" value="" size="30"/><br />
OR<br />
Acres:<input name="acres" type="text" value="" size="30"/><br /><br />
Number of Gate Openings:<input name="gate_opening" type="text" value="" size="30"/>
</td>
</tr>
</table><br><br>
<input type="submit" value="Send email"/>
</form>
<?php
} else {
// Grab forum elements and push into variables for the email
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$company_name = $_REQUEST['company_name'];
$install_address = $_REQUEST['install_address'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state'];
$zip = $_REQUEST['zip'];
$description = $_REQUEST['description'];
$corners = $_REQUEST['corners'];
$linear = $_REQUEST['linear'];
$acres = $_REQUEST['acres'];
$gate_opening = $_REQUEST['gate_opening'];
//Build Email
$message="$name<br />
$email<br />
$phone<br />
$company_name<br />
$install_address<br />
$city<br />
$state<br />
$zip<br />
$description<br />
$corners<br />
$linear<br />
$acres<br />
$gate_opening<br />";
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($install_address="")||($city="")||($state="")|| ($zip=""))
{
echo "Please fill the required fields. Click here to try again.";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Blue Ridge Fencing - Quote Forum";
mail("info#blueridgefenceco.com", $subject, $message, $from);
echo "Email sent! We will get back to you as soon as possible.";
}
}
?>
Thank you so much for you help!
For some reason, the options are not showing up in my email. I can get the email to send just fine. I can see the body and all its comments, but none of the entries that the user made. I know I am doing something wrong, but I cannot determine what it is.
Also, feel free to mock me if it looks horrible. :)
$ToEmail = 'dmandrade1978#gmail.com';
$EmailSubject = 'Message from web page!!';
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$urphone = $_POST['urphone'];
$event = $_POST['event'];
$date = $_POST['date'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$hearaboutus = $_POST['hearaboutus'];
$body = <<<EMAIL
Email: $email <br />
Name: $name <br />
Comment: $comment <br />
Phone: $urphone <br />
Date: $urdate <br />
Comment: $comment <br />
How did you hear?: $hearaboutus <br />
Mail optiom: $mail <br />
EMAIL;
$header = "Content-type: text/html\r\n";
mail("$ToEmail", "$EmailSubject", "$body", "$header");
echo ("Message Sent!");
?>
<td class = "form">
<form action="?" method="get" enctype="text/plain">
<p class = "form">Name:<br />
<input type="text" name="name" id="name" /></p>
<p class = "form">E-mail:<br />
<input type="text" name="email" id="email" /></p>
<p class = "form">Phone #:<br />
<input type="text" name="urphone" id="urphone" /></p>
<p class = "form">Event type:<br />
<input type="text" name="event" id="event" /></p>
<p class = "form">Date of event:<br />
<input type="text" name="date" id="date" /></p>
<p class = "form" >Prefered method of contact:<br />
<span class = "contact">
<input type="radio" name="phone" id="phone" /> Phone<br />
<input type="radio" name="mail" id="mail" /> E-mail<br />
</span></p>
<p class = "form">How did you hear about us?:<br />
<select name="hearaboutus" id="hearaboutus" />
<option value="internet">Internet</option>
<option value="word of mouth">Friend/Family</option>
<option value="magazine">Magazine</option>
<option value="other">Other</option>
</select></p>
<p class = "form">Message, questions, or availability:<br />
<textarea rows="10" cols="30" name="comment" id="comment">
</textarea></p>
<input type="submit" value="Send email to us" id="submit">
<input type="reset" value="Reset and start over">
</form>
Change method="get"
to
method="post"
and remove enctype . It's not required in this case.
Also, why is there a ? in your action? You can keep action blank as it is posting to the same page.
To make things even simpler for you, copy paste the below code and run the file again
if(isset($_POST['submit']))
{
$ToEmail = 'dmandrade1978#gmail.com';
$EmailSubject = 'Message from web page!!';
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$urphone = $_POST['urphone'];
$event = $_POST['event'];
$date = $_POST['date'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$hearaboutus = $_POST['hearaboutus'];
$body = <<<EMAIL
Email: $email <br />
Name: $name <br />
Comment: $comment <br />
Phone: $urphone <br />
Date: $urdate <br />
Comment: $comment <br />
How did you hear?: $hearaboutus <br />
Mail optiom: $mail <br />
EMAIL;
$header = "Content-type: text/html\r\n";
mail("$ToEmail", "$EmailSubject", "$body", "$header");
echo ("Message Sent!");
}
?>
<td class = "form">
<form action="" method="post">
<p class = "form">Name:<br />
<input type="text" name="name" id="name" /></p>
<p class = "form">E-mail:<br />
<input type="text" name="email" id="email" /></p>
<p class = "form">Phone #:<br />
<input type="text" name="urphone" id="urphone" /></p>
<p class = "form">Event type:<br />
<input type="text" name="event" id="event" /></p>
<p class = "form">Date of event:<br />
<input type="text" name="date" id="date" /></p>
<p class = "form" >Prefered method of contact:<br />
<span class = "contact">
<input type="radio" name="phone" id="phone" /> Phone<br />
<input type="radio" name="mail" id="mail" /> E-mail<br />
</span></p>
<p class = "form">How did you hear about us?:<br />
<select name="hearaboutus" id="hearaboutus" />
<option value="internet">Internet</option>
<option value="word of mouth">Friend/Family</option>
<option value="magazine">Magazine</option>
<option value="other">Other</option>
</select></p>
<p class = "form">Message, questions, or availability:<br />
<textarea rows="10" cols="30" name="comment" id="comment">
</textarea></p>
<input type="submit" name="submit" value="Send email to us" id="submit">
<input type="reset" value="Reset and start over">
</form>
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP Mail stops working without me editing the code
I've had a problem with a clients mail function for a while. The thing is that the mail I use to receive the mails stops receiving mails from time to time. I've noticed this because when I change from my clients mail (info#allflytt.com) to my own (daniel#codia.se) it starts working properly. Also the "success function" gives me the message "The mail was not sent." when I use my clients mail (info#allflytt.com). So the problem seems to be located in the mailadress wich somehow, sometimes, doesn't accept the mails. This happens a couple of times every day and all I can do is wait for it to work again. I've posted the code below.
<?php
if(isset($_POST['submit'])){
$mottagare = 'info#allflytt.com';
$titel = 'Meddelande';
$namn = strip_tags($_POST['namn']);
$foretag = strip_tags($_POST['foretag']);
$adress = strip_tags($_POST['adress']);
$postnr = strip_tags($_POST['postnr']);
$ort = strip_tags($_POST['ort']);
$telefon = strip_tags($_POST['telefon']);
$epost = strip_tags($_POST['epost']);
$meddelande = strip_tags($_POST['meddelande']);
$meddelande=nl2br($meddelande);
$body =
"
Namn: <b>". $namn ."</b><br />
Företag: <b>". $foretag ."</b><br />
Adress: <b>". $adress ."</b><br />
Postnr: <b>". $postnr ."</b><br />
Ort: <b>". $ort ."</b><br />
Telefon: <b>". $telefon ."</b><br />
E-post: <b>". $epost ."</b><br /><br />
Meddelande: <b><br />". $meddelande
;
$headers = 'From: '. $namn .' <webmaster#allflytt.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$success = mail($mottagare, $titel, $body, $headers);
}
?>
<?php
if(!($success)){
echo "<p class=\"field_error\">The mail was not sent.</p>";
}
?>
<?php
if($success){
echo "<p class=\"p_success\">Great! The mail was sent.</p>";
}
?>
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<p>
<label for="namn">Namn: *</label><br />
<input type="text" name="namn" id="namn" class="text" tabindex="15" />
<br />
<label for="foretag">Företag:</label><br />
<input type="text" name="foretag" id="foretag" class="text" tabindex="20" />
<br />
<label for="adress">Adress:</label><br />
<input type="text" name="adress" id="adress" class="text" tabindex="30" />
<br />
<label for="postnr">Postnummer:</label><br />
<input type="text" name="postnr" id="postnr" class="text_medium" tabindex="40" />
<br />
<label for="ort">Ort:</label><br />
<input type="text" name="ort" id="ort" class="text" tabindex="50" />
<br />
<label for="telefon">Telefon: *</label><br />
<input type="text" name="telefon" id="telefon" class="text" tabindex="60" />
<br />
<label for="epost">E-post:</label><br />
<input type="text" name="epost" id="epost" class="text" tabindex="70" />
<br />
<label for="meddelande">Meddelande: *</label><br />
<textarea name="meddelande" id="meddelande" class="textarea" tabindex="80"></textarea>
<br />
<input type="submit" name="submit" value="Skicka" class="submit" />
</p>
</form>
The problem is likely with the $namn variable, which can get practically any value, and therefore could either not be a valid e-mail at all, or could be an e-mail that's being blocked by the recipient.
Firstly you should make sure that $namn is a valid e-mail, but personally I would recommend that you use a single constant address for your From, preferably one the domain of which resolves to your mail server's IP.
Problem solved. Changed to a new server host. No issues any more!
I need your help. So the problem is that I've done some coding but I don't know why it doesn't work when page loads. But when I trigger any button (Save Info Modification Or Cancel Info Modification) it works.
php code :
if(isset($_POST['nametb']) && isset($_POST['usernametb']) && isset($_POST['emailtb']) && isset($_POST['confirmtb']) && isset($_POST['abouttb']) && isset($_POST['interesttb']) && isset($_POST['dreamtb']) && isset($_POST['liketb']) && isset($_POST['schooltb']) && isset($_POST['schoolyrtb']) && isset($_POST['occupationtb']) && isset($_POST['occupationyrtb'])){
$select_info = "SELECT * from user_info WHERE id='$user_id'";
if($select_info_run = #mysql_query($select_info)){
$namedb = mysql_result($select_info_run, 0, 'name');
$usernamedb = mysql_result($select_info_run, 0, 'username');
$emaildb = mysql_result($select_info_run, 0, 'email');
$confirmdb = mysql_result($select_info_run, 0, 'email');
$aboutdb = mysql_result($select_info_run, 0, 'about');
$interestdb = mysql_result($select_info_run, 0, 'interest');
$dreamdb = mysql_result($select_info_run, 0, 'dream');
$likedb = mysql_result($select_info_run, 0, 'like');
$schooldb = mysql_result($select_info_run, 0, 'school');
$schoolyrdb = mysql_result($select_info_run, 0, 'schoolyr');
$occupationdb = mysql_result($select_info_run, 0, 'occupation');
$occupationyrdb = mysql_result($select_info_run, 0, 'occupationyr');
}
else{
echo 'Server down :(';
}
}
else{
echo server down :(';
}
html code :
<form action="<?php if(isset($current_file)){ echo $current_file; } ?>" method="POST">
<fieldset id="fieldset1">
<legend style="font-family: Ubuntu; font-size:20px;">Info</legend>
<label id="name" title="Name" for="textbox1">Name :</label>
<label id="username" title="UserName" for="textbox2">UserName :</label>
<label id="email" title="Email" for="textbox3">Email :</label>
<label id="confirm" title="Confirm Email" for="textbox4">Confirm :</label>
<br />
<input type="text" id="textbox1" name="nametb" value="<?php if(isset($namedb)){ echo $namedb; } ?>" />
<input type="text" id="textbox2" name="usernametb" value="<?php if(isset($usernamedb)){ echo $usernamedb; } ?>" />
<input type="text" id="textbox3" name="emailtb" value="<?php if(isset($emaildb)){ echo $emaildb; } ?>" />
<input type="text" id="textbox4" name="confirmtb" value="<?php if(isset($confirmdb)){ echo $confirmdb; } ?>" />
<br /><br />
<div id="hrln"><hr /></div>
<label id="about" title="About you" for="textarea1">About :</label>
<label id="interest" title="You are interested in?" for="textarea2">Interested in :</label>
<br />
<textarea id="textarea1" name="abouttb"><?php if(isset($aboutdb)){ echo $aboutdb; } ?></textarea>
<textarea id="textarea2" name="interesttb"><?php if(isset($interestdb)){ echo $interestdb; } ?></textarea>
<br /><br /><br /><br /><br /><hr />
<label id="dream" title="Your Dream?" for="textarea3">Dream :</label>
<label id="like" title="What do you like?" for="textarea4">You like :</label>
<br />
<textarea id="textarea3" name="dreamtb"><?php if(isset($dreamdb)){ echo $dreamdb; } ?></textarea>
<textarea id="textarea4" name="liketb"><?php if(isset($likedb)){ echo $likedb; } ?></textarea>
<br /><br /><br /><br /><br /><hr />
<label id="education" title="Your school" for="textbox5">School | University :</label>
<label id="educationyr" title="Year" for="textbox6">Year :</label>
<br />
<input type="text" name="schooltb" id="textbox5" value="<?php if(isset($schooldb)){ echo $schooldb; } ?>" />
<input type="text" name="schoolyrtb" id="textbox6" value="<?php if(isset($schoolyrdb)){ echo $schoolyrdb; } ?>" />
<br /><br /><hr />
<label id="occupation" title="Occupation" for="textbox7">Occupation :</label>
<label id="occupationyr" title="Year" for="textbox6">Year :</label>
<br />
<input type="text" id="textbox7" name="occupationtb" value="<?php if(isset($occupationdb)){ echo $occupationdb; } ?>" />
<input type="text" id="textbox8" name="occupationyrtb" value="<?php if(isset($occupationyrdb)){ echo $occupationyrdb; } ?>" />
<br /><br /><hr />
<label id="passwords" title="For Security Purpose" for="textbox9">Password :</label>
<input type="password" id="textbox9" name="passwordstb" />
<input type="submit" value="Save Info Modification" name="save" id="button1" />
<input type="submit" value="Cancel Info Modification" name="cancel" id="button2" />
</fieldset>
</form>
Do you want the form to display? Then, get rid of that echo in the last "else". Then the form will display. When a user clicks the submit button, the form will post that information to the page.
Also, your 2nd "else{ echo server down :('; }" is missing a quote before 'server down :(';
The key to your problems is what I call "isolation": you need to isolate what is causing the issue. I recommend the "comment-out-code-and-refresh-page" technique if you're pressed for time. But it's far better to analyze and interpret your code and UNDERSTAND why it's not doing what you want.
It runs when you click the buttons because of this:
if(isset($_POST['nametb']) && isset($_POST['usernametb']) && isset($_POST['emailtb']) &&
isset($_POST['confirmtb']) && isset($_POST['abouttb']) && isset($_POST['interesttb']) &&
isset($_POST['dreamtb']) && isset($_POST['liketb']) && isset($_POST['schooltb']) &&
isset($_POST['schoolyrtb']) && isset($_POST['occupationtb']) &&
isset($_POST['occupationyrtb'])){
Your if statement is checking if anything in the POST array is set before doing anything.
This is sent by the form when you click a submit button (which is either button, it seems).
If you are trying to populate the fields on page load, you need to move your SELECT statement an related code outside of that if statement. Since it seems you would be using this form to update database data, you should put your INSERT/UPDATE statements inside the if statement so that they won't run until you click the submit button (pending other logical operations to take into account WHICH button was pressed.).
My php script to send mail is as follows :
<?php
if (isset($_POST['submit'])) {
$to='info#animalswecare.com';
$fname=stripslashes($_POST['fname']);
$email=$_POST['email'];
if (get_magic_quotes_gpc())
$email = stripslashes($email);
//$email=trim($email, '/');
$msg=$_POST['msg'];
$msg=stripslashes($msg);
$message="Name: $fname\n" ."Message: $msg\n";
mail($to,$subject,$message,'From:'.$email) ;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact us">
<label>Name:</label>
<input type="text" name="fname" value=<?php if(!empty($fname)) echo $fname; ?> /><br />
<label>Email:</label>
<input type="text" name="email" value=<?php if (!empty($email)) echo $email; ?> /><br />
<label>Message:</label>
<textarea name="msg" rows="5"><?php if (!empty($msg)) echo $msg; ?></textarea> <br />
<input type="submit" name="submit" value="Post" />
</form>
But when the form appears, there is a / added in every field.
I have tried using trim, rtim, get magic quotes and stripslashes but nothing is working.
It because your value='s are not being ended.
Try this: <input type="text" name="fname" value="<?php if(!empty($fname)) echo $fname; ?>" /> and apply the same learning's to all of the inputs.
Also I re-formatted your code and added label in the CSS..so you don't have use those ugly line-spaces.
<?php
if (isset($_POST['submit'])) {
$to = 'info#animalswecare.com';
$fname = stripslashes($_POST['fname']);
$email = $_POST['email'];
if (get_magic_quotes_gpc()) {
$email = stripslashes($email);
}
// $email = trim($email, '/');
$msg = $_POST['msg'];
$msg = stripslashes($msg);
$message = "Name: $fname\n" ."Message: $msg\n";
mail($to, $subject, $message, 'From:' . $email);
}
?>
<style>
label {width: 120px;}
</style>
<form action="" method="post">
<label>Name:</label>
<input type="text" name="fname" value="<?php if(!empty($fname)) echo $fname; ?>" /><br />
<label>Email:</label>
<input type="text" name="email" value="<?php if (!empty($email)) echo $email; ?>" /><br />
<label>Message:</label>
<textarea name="msg" rows="5"><?php if (!empty($msg)) echo $msg; ?></textarea><br />
<input type="submit" name="submit" value="Post" />
</form>
try adding " " around the value attribute
ie
<input type="text" name="email" value="<?php if (!empty($email)) echo $email; ?>" />
This will teach you to follow standards and always enclose tag parameter values in quotes
First of all, don't use stripslashes(). Simply disable magic_quotes_gpc completely, using the php.ini file or .htaccess. If you can't, view the accepted answer to this question: How to turn off magic quotes on shared hosting?
About your error...
value=<?php if (!empty($email)) echo $email; ?> />
If you look, you didn't put the quotes around the attribute "value".
value="<?php if (!empty($email)) echo $email; ?>" />
will fix it