Jump to content

email is not sent


danielbala
 Share

Recommended Posts

Hi.

Iam trying to sent this form values to my email

 

Its not working

Can anyone help to solve this..

 

this is the form

<form method="POST" action="sendemail.php">
<table width="450px">
<tr>
<td valign="top">
  <label for="name">Name </label>
</td>
<td valign="top">
  <input  type="text" name="name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
  <label for="organisation">Organisation </label>
</td>
<td valign="top">
  <input  type="text" name="organisation" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
  <label for="contact">Contact no </label>
</td>
<td valign="top">
  <input  type="text" name="contact" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
  <label for="remarks">Remarks</label>
</td>
<td valign="top">
<textarea  name="remarks" maxlength="50" ></textarea>
  
</td>
</tr>
<tr>
<td valign="top">
  <label for="designation">Designation </label>
</td>
<td valign="top">
  <input  type="text" name="designation" maxlength="50" size="50">
</td>
</tr>
<tr>
<td valign="top">
  <label for="email">E-mail </label>
</td>
<td valign="top">
<input  type="text" name="email" maxlength="50" size="40">
   </td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
  <input type="submit" value="Submit"> <input type="reset" value="Reset"> 
</td>
</tr>
</table>

</form>

 

sendemail.php

<?php
session_start();
if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "-----------------l@gmail.com";
    $email_subject = "Contact Details";
     
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['organisation']) ||
        !isset($_POST['email']) ||
	!isset($_POST['contact']) ||
        !isset($_POST['designation']) ||
        !isset($_POST['remarks'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
     
    $name = $_POST['name']; 
    $organisation = $_POST['organisation']; 
    $email = $_POST['email']; 
    $contact = $_POST['contact']; 
$designation = $_POST['designation']; 
    $remarks = $_POST['remarks']; 
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$name)) {
    $error_message .= 'Name you entered does not appear to be valid.<br />';
  }
    if(strlen($remarks) < 2) {
    $error_message .= 'The Remarks you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "Name: ".clean_string($name)."\n";
    $email_message .= "Organisation: ".clean_string($organisation)."\n";
$email_message .= "Contact No: ".clean_string($contact)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "Remarks: ".clean_string($remarks)."\n";
    $email_message .= "Designation: ".clean_string($designation)."\n";
     
     
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
}?>
<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.



Link to comment
Share on other sites

Hello,

 

Quick look at the code and you need to chnage

 

function died($error) {

 

to

 

function die($error) {

 

This should show you where the code is showing the error.

 

 

*buzzer sound*

You cannot override existing PHP functions.

 

 

As for the problem, "it's not working" is useless to us.

Link to comment
Share on other sites

sorry i copied the wrong part...

 

died('We are sorry, but there appears to be a problem with the form you submitted.');   

 

that should be die('We are sorry, but there appears to be a problem with the form you submitted.');   

Link to comment
Share on other sites

sorry i copied the wrong part...

 

died('We are sorry, but there appears to be a problem with the form you submitted.');   

 

that should be die('We are sorry, but there appears to be a problem with the form you submitted.');   

Still wrong. He's defined died as a function. He can call it fred for all he wants, it's his function.

Link to comment
Share on other sites

Sorry, but "it's not working" is not going to get you any answers. WHAT isn't working? Is the email not sending at all? Is the email sending but with incorrect/unexpected data? Is there a PHP error? We aren't looking at your monitor, we don't know what "isn't working" means.

 

Also, remove the @ symbol from the mail function to see if it is producing errors.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.