jonathanellis Posted February 6, 2008 Share Posted February 6, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/89660-small-php-problem/ Share on other sites More sharing options...
jonathanellis Posted February 6, 2008 Author Share Posted February 6, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459391 Share on other sites More sharing options...
mmarif4u Posted February 6, 2008 Share Posted February 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459394 Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 mail() is kind of unstable in that many hosts will block email sent by it. Look at phpmailer (google: phpmailer) as an alternative that is more reliable. Quote Link to comment https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459398 Share on other sites More sharing options...
jonathanellis Posted February 6, 2008 Author Share Posted February 6, 2008 suppose I add the $header, where do I place it in the code. I am still very new to php. And I looked into the phpmailer. I don't have control of the php on my server, so I don't know how to install phpmailer or implement the script into my website. Quote Link to comment https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459405 Share on other sites More sharing options...
mmarif4u Posted February 6, 2008 Share Posted February 6, 2008 Phpmailer is the best choice if you can playing around with it. About headers. headers has to placed for your $from variable. Where u add $from just add $headers and change the from email and cc(if u want). Quote Link to comment https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459407 Share on other sites More sharing options...
jonathanellis Posted February 6, 2008 Author Share Posted February 6, 2008 because I don't have control over my server, it's not even my server, i can't modify the php files. how can i implement the phpmailer? Quote Link to comment https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459453 Share on other sites More sharing options...
jonathanellis Posted February 6, 2008 Author Share Posted February 6, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/89660-small-php-problem/#findComment-459515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.