Jump to content


Photo

PHP MAIL NOT SENDING

php mail forum contactforum sending

  • Please log in to reply
9 replies to this topic

#1 YousefDiab

YousefDiab

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 20 August 2014 - 12:06 AM

<?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 :)

 



#2 ginerjm

ginerjm

    Advanced Member

  • Members
  • PipPipPip
  • 1,706 posts
  • LocationVoorheesville NY

Posted 20 August 2014 - 09:24 AM

your mail statement has an error in it?


Edited by ginerjm, 20 August 2014 - 09:25 AM.

JG

PS - If you're posting here you should be using:
        error_reporting(E_ALL | E_NOTICE);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!


#3 BuildMyWeb

BuildMyWeb

    Advanced Member

  • Members
  • PipPipPip
  • 110 posts
  • LocationNY

Posted 20 August 2014 - 12:13 PM

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, 20 August 2014 - 12:15 PM.

Freelance Web Developer | Web Hosting | PHP Applications
Web Development, Hosting, Graphic Design, SEO


#4 AP_King7

AP_King7

    Newbie

  • New Members
  • Pip
  • 9 posts

Posted 20 August 2014 - 01:34 PM

How do you loop through POST variables there?



#5 AP_King7

AP_King7

    Newbie

  • New Members
  • Pip
  • 9 posts

Posted 20 August 2014 - 01:35 PM

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, 20 August 2014 - 01:36 PM.


#6 CroNiX

CroNiX

    Advanced Member

  • Gurus
  • 873 posts
  • LocationPortland, OR

Posted 20 August 2014 - 01:50 PM

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] . " - ";
    }
}


#7 CroNiX

CroNiX

    Advanced Member

  • Gurus
  • 873 posts
  • LocationPortland, OR

Posted 20 August 2014 - 01:56 PM

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



#8 AP_King7

AP_King7

    Newbie

  • New Members
  • Pip
  • 9 posts

Posted 20 August 2014 - 02:12 PM

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?



#9 BuildMyWeb

BuildMyWeb

    Advanced Member

  • Members
  • PipPipPip
  • 110 posts
  • LocationNY

Posted 20 August 2014 - 02:39 PM

$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);


Freelance Web Developer | Web Hosting | PHP Applications
Web Development, Hosting, Graphic Design, SEO


#10 ginerjm

ginerjm

    Advanced Member

  • Members
  • PipPipPip
  • 1,706 posts
  • LocationVoorheesville NY

Posted 20 August 2014 - 03:19 PM

I do believe that the mail function requires the headers to be in the 4th (missing) parameter.  For one thing you absolutely have to provide a from address there.


JG

PS - If you're posting here you should be using:
        error_reporting(E_ALL | E_NOTICE);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com