Jump to content

Small PHP problem


jonathanellis

Recommended Posts

Hello,

 

I am very new to php. I have managed to write some script to handle emailing the contents of a form. I have everything working the way I want it, the only problem is the actual email that is supposed to get sent, doesn't ever get sent. Thank you to whoever can help me with some insight!

 

<?php
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitoremail'];
$visitorphone = $_POST['visitorphone'];
$visitormessage = $_POST['visitorcomment'];

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<p>Please enter valid e-mail address.</p>\n";
$badinput = "<p>Your form could not be submitted.</p>\n";
echo $badinput;
die ("<p>Please go back and resubmit.</p>");
}

if(empty($visitor) || empty($visitormail) || empty($visitorphone) || empty($visitormessage )) {
echo "<p>Please ensure all fields are complete.</p>\n";
die ("<p>Please go back and resubmit.</p>");
}

$attn = "Email from Website" ;
$subject = $attn;
$message = "
Attention: $attn \n
Message: $visitormessage \n
From: $visitor ($visitormail)\n
Phone: $visitorphone \n";

$from = "From: $visitormail\r\n";


mail("[email protected]", $subject, $message, $from);

?>

 

This page with the form calling the php can be found online at http://www.versionthree.ca/staging/volume/contact.html

the actual php page is http://www.verisonthree.ca/staging/volume/sendEmail.php

Link to comment
https://forums.phpfreaks.com/topic/89660-small-php-problem/
Share on other sites

Sorry, I noticed a few errors with naming on my part. The revised php is:

 

<?php
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$visitorphone = $_POST['visitorphone'];
$visitorcomment = $_POST['visitorcomment'];

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<p>Please enter valid e-mail address.</p>\n";
$badinput = "<p>Your form could not be submitted.</p>\n";
echo $badinput;
die ("<p>Please go back and resubmit.</p>");
}

if(empty($visitor) || empty($visitormail) || empty($visitorphone) || empty($visitorcomment )) {
echo "<p>Please ensure all fields are complete.</p>\n";
die ("<p>Please go back and resubmit.</p>");
}

$attn = "Email from Website" ;
$subject = $attn;

$message = "
Attention: $attn \n
Message: $visitorcomment \n
From: $visitor ($visitormail)\n
Phone: $visitorphone \n";

$from = "From: $visitormail\r\n";


mail("[email protected]", $subject, $message, $from);

?>

Link to comment
https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459391
Share on other sites

Add header to email and then try it.

 

$headers = 'From: Team <[email protected]>' . "\r\n" .
    'Cc: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion() ."\r\n".
    'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n";

 

Be sure that from the sending domain is ur host.

Link to comment
https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459394
Share on other sites

this is what i have now, after reading a bit about phpmailer.

 

<?php
$mail->PluginDir = "http://www.versionthree.ca/staging/volume/";
require("http://www.versionthree.ca/staging/volume/class.phpmailer.php");

$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$visitorphone = $_POST['visitorphone'];
$visitorcomment = $_POST['visitorcomment'];

$mail = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.versionthree.ca"; // SMTP server
$mail->From = "[email protected]";
$mail->FromName = "Unit Tester";
$mail->AddAddress("[email protected]");

$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send())
{
   echo '<p>Message was not sent.</p>';
   echo '<p>Mailer error: ' . $mail->ErrorInfo . '</p>';
}
else
{
   echo '<p>Message has been sent.</p>';
}

 

It still is not sending the email for me. What am i doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459515
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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