Question:
Can someone help me with coding please?
Top Notch Web Creations
2014-07-08 19:23:52 UTC
I need help with my php coding. I need to know what I messed up on. I am trying to have my contact form for my website work right. When I hit submit it goes to a blank page and I don't receive an email. I have a contact.html that works, but my php is separate. I have "mailer.php" as my action for my form in the html and I save my php as "mailer.php". Not sure what I am messing up on. Please help me. I am new to php and I need someone to guide me through it. I am going to add my php script to a comment because it will not fit in this one.
Three answers:
?
2014-07-08 23:20:43 UTC
Without seeing the pieces of code you have written, it is not possible to give you an answer, nor to give you examples: the answers above may be ok, but may also be completely out of place! (and there are a few inconsistencies/procedural mistakes in their code)

Phpmailer is not yet for you: too complex. Using classes to perform mailing is a very stupid approach: the plain coding is MUCH easier! As to use an API from external source, leave that until you have mastered all coding: APIs are often extremely complex to use...



You appear, however, to have the correct link between files (your contact.html and your mailer.php). Since you receive a blank page, you probably have called mailer.php correctly.

Remain to see how you deal with the request sent by contact.html, on which we have no details...

Go to http://webprosonly.com and download the free scripts "form to email" and "email newsletter". These should help you to understand how to achieve your purpose.

Good luck.
Nicole Anne
2014-07-08 19:56:34 UTC
you can also try the PHPMailer class then use Google API to send the mail using your gmail account.

Try this code. It works for me. :)



//$info contains the details for the receiver and mail contents.

function gmail($info){

$account=array();

$subject = 'Payment Successful';

$gmail='nicolelopez@gmail.com'; //your google mail address

$password='nicoleanne'; //your gmail password

$name = $info['first_name']." ".$info['last_name'];



require_once('PHPMailer/class.phpmailer.php');

//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded



$mail = new PHPMailer();

$body = "Congratulations $name!

We already received your payment worth ".$info['amount']." USD.





Enjoy your trip and we look forward in dealing with you again. Thank you.

";



$mail->IsSMTP(); // telling the class to use SMTP

//$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)

// 1 = errors and messages

// 2 = messages only

$mail->SMTPAuth = true; // enable SMTP authentication

$mail->SMTPSecure = "tls"; // sets the prefix to the servier

$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server

$mail->Port = 587; // set the SMTP port for the GMAIL server

$mail->Username = "{$gmail}"; // GMAIL username

$mail->Password = "{$password}"; // GMAIL password



$mail->SetFrom("{$gmail}", 'Nicole Anne'); // you can change the second parameter of this to your name instead



$mail->Subject = $subject;



$mail->MsgHTML($body);



$address = $info['email'];

$mail->AddAddress($address, $name);





$mail->Send();





Hope it helps :)
Top Notch Web Creations
2014-07-08 19:24:08 UTC

$sendMessage = false;

if (isset ($_REQUEST['message']) && isset($_REQUEST['email']) &&

isset($_REQUEST['name']))

{

$email = $_REQUEST['email'];

$name = $_REQUEST['name'];

$subject = $_REQUEST['subject'];

$message = $_REQUEST['message'];

if (strlen($message) > 0 && strlen($email) > 0 && strlen($subject) > 0 && strlen($name) > 0)

{ $sendMessage = true;}

}



if (isset ($_REQUEST['posted']) && (!$sendMessage))

{ echo "Please fill in all the values";}



if ($sendMessage)

{ //Jogden614@yahoo.com

$to= "Jogden614@yahoo.com";

$subject= "Website Feedback.";

$headers= "Mime Version: 1.0". "\r\n";

$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

$headers .= "From: $email\r\n"; // setup the from field for e-mail

$headers .= "Content-type: text/html\r\n"; // setup e-mail format



$success = mail($to, $subject, $message, $headers);

if ($success) // if successful display the message & success message

{

echo "You sent the following:
$message

";

echo "

Form submitted successfully.

";

}

else // If not successful let the user know

{ echo "An error occurred when trying to send the e-mail."; }

}

?>


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...