Jump to content

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("undisclosedEmailAddress@something.com", $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("jon@versionthree.ca", $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 <support@domain.com>' . "\r\n" .
    'Cc: test@yahoo.com' . "\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 = "client@yahoo.com";
$mail->FromName = "Unit Tester";
$mail->AddAddress("jon@versionthree.ca");

$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

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.