-1

i cant get the php to run. its not sending any emails to my account.

Im new at learning php. I have a the basic understanding of html and css. I had no idea on how to complete this. ive tried to copy other peoples code and adapt it to suit mine.

php code:

<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];

//send mail 
$to='dadjus555@gmail.com';
$subject='New ';
$body='<html>
<body>
<h3>Feedback</h3>
<hr>

<p> Name : '.$name.'</p>
<br>
<p> Job : '.$job.'</p>
<br>
<p> Co : '.$co'</p>
<br>
<p> Phone : '.$phone.'</p>
<br>
<p> Email : '.$email.'</p> 
<br>
<p> Snapchat : '.$snap.'</p>
<br>
<p> Instagram : '.$insta.'</p>
<br>
<p> Facebook : '.$facebook.'</p>
<br>
<p> Twitter : '.$twitter.'</p>
<br>
</body>
</html>';

$headers  ="From:".$name."<".$email.">\r\n";
$headers .="reply-To:".$email."\r\n";
$headers .="NINE-Version: 1.0\r\n";
$headers .="Content-type: text/html; charset=utf-8";

//sending process
$send=mail($to, $subject, $body, $headers);
$confirm=mail($user, $usersubject, $userheaders,$usermessage );

if($send && $confirm){
echo "success";
}

else{
echo "Failed";
}

}
?>

Html code:

<form>
<fieldset><legend>Personal</legend>
<label for="field1"><span>Name <span class="required">*</span></span><input 
type="text" class="input-field" name="name" value="" /></label>
<label for="field1"><span>Occupation</span></span><input type="text" 
class="input-field" name="job" value="" /></label>
<label for="field1"><span>what company?</span></span><input type="text" 
class="input-field" name="co" value="" /></label>
<label for="field1"><span>Phone <span class="required">*</span></span><input 
type="text" class="input-field" name="phone" value="" /></label>
<label for="field2"><span>Email <span class="required">*</span></span><input 
type="email" class="input-field" name="email" value="" /></label>
<label for="field1"><span>Snapchat </span></span><input type="text" 
class="input-field" name="snap" value="" /></label>
<label for="field1"><span>Instagram </span></span><input type="text" 
class="input-field" name="insta" value="" /></label>
<label for="field1"><span>Facebook </span></span><input type="text" 
class="input-field" name="facebook" value="" /></label>
<label for="field1"><span>Twitter </span></span><input type="text" 
class="input-field" name="twitter" value="" /></label>
<label for="field3"><span>Kik</span></span><input type="text" class="input- 
field" name="kik" value="" /></label>
</label>
</fieldset>
</form>

When someone puts text into the form and presses the submit button, the information will be emailed to my inbox

1 Answers1

0

You cannot send/receive your mail because you have some errors:

  1. headers are wrongs
  2. your mail function is called in the wrong manner
  3. you have some variables not included in your code and that you call only when try to send your mail

Here you can see my changes:

$headers  = "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8";

// sending process
$send = mail($to, $subject, $body, $headers);
$confirm = mail($user, $usersubject, $usermessage, $userheaders);

if ($send && $confirm) {
  echo "success";
} else {
  echo "Failed";
}

These variables do exist or not?

$user $usersubject $usermessage $userheaders

As you can see at point 2... you call:

mail($user, $usersubject, $userheaders,$usermessage );

while should be:

mail($user, $usersubject, $usermessage, $userheaders);

So you cannot check and get the correct response from php.

I suggest separate the 2 mail calls...

if ($send) {
  echo "1st mail sent with success";
} else {
  echo "1st mail is failed";
}

if ($confirm) {
  echo "2nd mail sent with success";
} else {
  echo "2nd mail is failed";
}

I hope this helps.

Alessandro
  • 900
  • 12
  • 23