Jump to content

PHP MAIL NOT SENDING


YousefDiab

Recommended Posts

<?php
$site_email = $row["example@madhost.co"];
$email25=$_REQUEST['email'];
$action=$_REQUEST['action'];
if ($action=="")    /* display the contact form */
    {
    ?>
          <form id="ContactForm" action="" method="POST" enctype="multipart/form-data">
           <input type="hidden" name="action" value="submit">
            <div>
              <div class="wrapper"> <span>Your Name:</span>
                <input type="text" class="input" name="name" maxlenght="15">
              </div>
              <div class="wrapper"> <span>Your E-mail:</span>
                <input type="text" class="input" name="email" >
              </div>
              <div class="textarea_box"> <span>Your Message:</span>
                <textarea name="textarea" cols="1" rows="1"></textarea>
              </div>
              <input type="submit" class="button1"> <a href="contact.php" class="button1">Clear</a> </div>
          </form>
           <?php
    } 
else                /* send the submitted data */
    {
    $name=$_REQUEST['name'];
    $email=$_REQUEST['email'];
    $message=$_REQUEST['textarea'];
    if (($name=="")||($email=="")||($message==""))
        {
        echo "All fields are required, please fill <a href=\"\">the form</a> again.";
        }
    else{        
        $from="From: $name<$email>\r\nReturn-path: $email";
        $subject= $subject1;
        mail($to =$site_email, $message, $from);
        echo "
        <div class=\"contactform\">
        Thank you for contacting us, please wait for our reply!
        </div>
        ";
        }
    }  
?> 

The only problem is that im not recieving the email :/

Any Help ?

I would really appreciate it and thank you :)

 

Link to comment
Share on other sites

try something more like the below

else
{
    $from        = "From: $name<$email>\r\nReturn-path: $email";
    $subject    = "Form Submission";
    $to            = "youremail@yahoo.com";
    $message    = "you likely will want to loop through your $_POST variables here";
    
    mail($to, $subject, $message);
    
    echo"
        <div class=\"contactform\">
            Thank you for contacting us, please wait for our reply!
        </div>
    ";
}

there is also an option fourth parameter in the mail() function.  preferable to use it well if you dont want your emails being dropped in spam folders, blocked, etc.

Edited by BuildMyWeb
Link to comment
Share on other sites

For instance how would I put this into $message?

<?php
  $aMeat = $_POST['tMeat'];
  if(empty($aMeat)) 
  {
    echo("You didn't select any meats.");
  } 
  else
  {
    $N = count($aMeat);
 
    echo("You ordered $N meat(s): ");
    for($i=0; $i < $N; $i++)
    {
      echo($aMeat[$i] . " - ").;
    }
  }
?>
Edited by AP_King7
Link to comment
Share on other sites

Problem is you're echoing the values, which will just go out to the browser. You want to add it to a string.

$aMeat = $_POST['tMeat'];
$message = '';
if(empty($aMeat)) 
{
   $message = "You didn't select any meats.";
} 
else
{
    $N = count($aMeat);
 
    $message = "You ordered $N meat(s): ";
    for($i=0; $i < $N; $i++)
    {
      //add this meat to the end of the $message string (string concatenation)
      $message .= $aMeat[$i] . " - ";
    }
}
Link to comment
Share on other sites

alternatively, since $aMeat is an array, you can use implode() on it, like

$N = count($aMeat);
$message = "You ordered $N meat(s): " . implode(', ', $aMeat);

Message would now be something like:

You ordered 1 meat(s): pork

or if there were more than one selected:

You ordered 3 meat(s): pork, beef, chicken

Link to comment
Share on other sites

I need all of the information to go into the browser as well.  I have it all set up to echo to the browser and it works perfectly, now I just need to send all of the different arrays in an e-mail message.  How do I echo them to the browser and add them to my message? Also, I am wanting to add more than just meats, I have other variables similar to $aMeat that I want to add in the message, is that possible this way?

Link to comment
Share on other sites


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

$to = "youremail@yahoo.com";
$subject = "submission data";

$fields             = array();
$fields["Name"]     = $name;
$fields["Email"]     = $email;

$message = "We have received the following information from a submission:\n\n";
foreach($fields as $a => $b)
{ $message .= sprintf("%30s: %s\n",$a,$b); }

mail($to, $subject, $message);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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