Jump to content

E-mail sent from script not working


confused and dazed

Recommended Posts

Hello internet.I am trying to send an e-mail within a script and it does not seem to be working.I echoed the e-mail address and name (in a previous version of the code I posted here) and it recognizes the form data e-mail address and name BUT there is no e-mail that is sent. Any ideas? <?php$con = mysql_connect("xxxx","xxxx","xxxx");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("xxxx", $con);$result = mysql_query("SELECT Member_id FROM selections WHERE name='$_POST[participantname]'", $con); $idnum = mysql_fetch_array($result);$memberid = $idnum['Member_id'];mail("$_POST[participantemail]","Your 2012 Selections","Your Selections have been registered","From:me_yup@hotmail.com"); mysql_close($con)?>

Link to comment
Share on other sites

You need to have a mail sever for mail() to work. If you are working on your computer you can install a free mail server, just do a search. If you are working off a hosting site, they most likely only turn on that feature for paying customers.

Link to comment
Share on other sites

if it was working, and then stopped working, wouldn't it have been worth asking your hosting company if something they might have done could have caused the issue? Hosts tends to update PHP/environments. Maybe it's cause your from email is hotmail, and that isn't what the domain of the sending mail domain is. also, have you checked the return value of mail() to make sure it is still working correctly? It returns true or false on execution. That would definitely be my first step towards debugging.http://php.net/manual/en/function.mail.php

Link to comment
Share on other sites

if(mail({.....}){  echo 'success';}else{  echo 'failure';}; //or assign the return value$mailReturnValue = mail({...}); if($mailReturnValue){  echo 'success';}else{  echo 'failure';};

Link to comment
Share on other sites

thescientist - that link pretty much is telling me I have no clue what the ###### is going on.I am so angry right now - godaddy wont do anything because they dont support custom scripting. I tried restoring all my files to a date I know it was working and that still did not do anything.It was working just fine... I deleted a couple files and then gone for good. I tried restoring to that date but still no e-mail is getting sent.I was soooo close.
Link to comment
Share on other sites

OK so let me try a different route... Here is the sample code in w3schools php e-mail section $to = someone@example.com; // I put $_POST[...] here becasue I want the user to specify where the e-mail is going$subject = "Test mail";$message = "Hello! This is a simple email message.";$from = someonelse@example.com; // here I put my myaddress@mydomain$headers = "From:" . $from;mail($to,$subject,$message,$headers);echo "Mail Sent."; O.K. so what file or code needs to accompany this to make an e-mail get sent to the user?GoDaddy is not being helpful - they want me to use thier webformmailer.php but I need to create my own custom forms so this wont work.I started looking at php.ini information (the link thescientist provided above - this is not a slam on you thescientist it is a slam on me) and quite honestly I just cant make sense of it.Can anyone guide my next steps so I can send e-mail?Thanks.

Link to comment
Share on other sites

O.K. so I have been doing a little reading up on this and I found this code. I want to run it by w3schools to make sure it is clean before I use it.The point of this code is to send the e-mails from my domain and I do see the code in there that does it (I bolded it). I tried sending e-mails to yahoo, gmail, ymail, hotmail from my domain and it worked just fine. So if this code is clean it appears it will allow me to send e-mails from my domain.Let me know what you think of this code before I use it. <?php$thankyou = "Thnks.html";$full_name = $_POST['Full_Name']; $company_name = $_POST['Company_Name']; $email_from = $_POST['Email_Address'];$telephone = $_POST['Telephone_Number']; $comments = $_POST['Requirements']; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string);} $email_message = "Read Message details below:\r\n";$email_message .= "-----------------------------------------\r\n";$email_message .= "Customer Name: ".clean_string($full_name)."\r\n";$email_message .= "Company Name: ".clean_string($company_name)."\r\n";$email_message .= "Email: ".clean_string($email_from)."\r\n";$email_message .= "Telephone: ".clean_string($telephone)."\r\n";$email_message .= "Requirements: ".clean_string($comments)."\r\n"; require_once "Mail.php";$from = "yourid@yourdomain.com"; \\the mail-iD under your domain$to = "yourgmail@gmail.com"; \\the TO gmail ID$subject = "PHP Enquiry form";$body = $email_message;$host = "mail.yourdomain.com"; \\ your domain mail server$username = "yourid@yourdomain.com"; \\the mail-id under your domain$password = "yourpassword"; \\your password for yourid@mydomain.com$headers = array ('From' => $from, 'To' => $to, 'Reply-To'=> $email_from, 'Subject' => $subject);$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));$mail = $smtp->send($to, $headers, $body);if (PEAR::isError($mail)){echo("<p>" . $mail->getMessage() . "<p>");}else{ header("Location: $thankyou");}?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...