My email code isn’t working.
<?php
if(isset($_POST['send'])){
$to = "info@erbimages.com" ; // change all the following to $_POST
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$subject2 = "Thank you for contacting us.";
$autoreply = "<html><body><p>Dear " . $name . ",</p><p>Thank you for registering with ERB Images.</p>
<p>To make sure that you continue to receive our email communications, we suggest that you add info@erbimages.com to your address book or Safe Senders list. </p>
<p>In Microsoft Outlook, for example, you can add us to your address book by right clicking our address in the
'From' area above and selecting 'Add to Outlook Contacts' in the list that appears.</p>
<p>We look forward to you visiting the site, and can assure you that your privacy will continue to be respected at all times.</p><p>Yours sincerely.</p><p>Edward R Benson</p><p>Edward Benson Esq.<br />Founder<br />ERB Images</p><p>www.erbimages.com</p></body></html>";
$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers2 .= 'From: noreply@erbimages.com' . "\r\n";
mail($from, $subject2, $autoreply, $headers2);
$send=false;
if($name == '') {$error= "You did not enter your name, please try again.";}
else {
if(!preg_match("/^[[:alnum:]][a-z0-9_.'+-]*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$/",$from)) {$error= "You did not enter a valid email address, please try again.";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
}
if(!isset($error) && !$send)
$error= "We have encountered an error sending your mail, please notify service@erbimages.com"; }
}// end of if(isset($_POST['send']))
?>
<?php include("http://erbimages.com/php/doctype/index.php"); ?>
<?php include("http://erbimages.com/php/head/index.php"); ?>
<div class="newsletter">
<ul>
<form method="post" action="http://lilyandbenson.com/newletter/index.php">
<li>
<input size="20" maxlength="50" name="Name" value="Name" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;">
</li>
<li>
<input size="20" maxlength="50" name="Email" value="Email" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;">
</li>
<li>
<input type="submit" name="send" value="Send" id="register_send">
</li>
</form>
<?php
?>
</ul>
<div class="clear"></div>
</div>
<div class="section_error">
<?php
if(isset($error))
echo '<span id="section_error">'.$error.'</span>';
if(isset($send) && $send== true){
echo 'Thank you, your message has been sent.';
}
if(!isset($_POST['send']) || isset($error))
?>
<div class="clear"></div>
</div>
</body>
</html>
Read the documentation here http://php.net/manual/en/function.mail.php
Specially this part:
“The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.
The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a ‘X-Warning’ header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.”
So you need to have
sendmailinstalled in your system, and the user running the webserver should have rights to send an email throughsendmail.Check
/var/log/apache2/error.log(if you are under Linux and you are using Apache server) or whatever log for your webserver to find any clue.