Question:
PHP email wont send to specified address?
Ryan Kelly
2012-04-30 14:21:55 UTC
on my simple site i have a button and a textbox next to it, i have an external email php script that sends an email to the specified address once the button has been clicked however i need to be able to email someone by putting in the textbox someones email address, the code so far is below. the problem im having is that it wont send to the specified email address in the textbox, please help thanks.

PHP

$Email_Name = $_GET['emailinput'];
$to = Email_Name;
$subject = "Test mail";
$message = "Hello!";
$from = "Ryan";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>


HTML below




Five answers:
anonymous
2012-04-30 20:00:48 UTC
Your current hosting package or service MUST allow SMTP ( http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol ) to work. Otherwise, no email can be sent.



Setting Up the SMTP Service: http://www.code-crafters.com/abilitymailserver1/tutorial_smtp.html



PHP: Sending Email Tutorial (Text/HTML/Attachments): http://www.webcheatsheet.com/php/send_email_text_html_attachment.php



Use any of the below sites to make the workable form you need:



Just follow the instructions for making it and uploading file(s).



Contact Form Generator: http://www.tele-pro.co.uk/scripts/contact_form/

WYSIWYG Form Maker (Easiest to Use): http://www.jotform.com/?gclid=CNKhqei1wJ4CFRQhnAod6laUqA

http://www.thesitewizard.com/wizards/feedbackform.shtml

http://www.form2email.net/

http://www.phpform.org/



Ron
Nik
2012-04-30 14:43:51 UTC
A few tips.



1)

Make sure your variables contain the data by echoing them out.



2)

type=button is not valid for a submit button





3)

This may need to be done online if you are not already as local servers need to be set up to send emails.



-----------

And finally here is a mail script I know works.



$subject = "Messages Received";



$message_body = "CONTENT HERE. \n";



$headers =

"From: YOUR EMAIL HERE" . "\r\n" .

"Reply-To: YOUR EMAIL HERE" . "\r\n" .

'X-Mailer: PHP/' . phpversion();



$mail_response = mail("THERE EMAIL HERE" , $subject, $message_body,

$headers);
?
2012-04-30 14:23:10 UTC
You forgot a $ in front of Email_Name.



So it should be:



$to = $Email_Name;





Also, and this is just me being a little nit-picky, but your variable names don't seem to follow any coherent and consistent standard, such a camel casing or another. You have one variable that is all lower case, another that starts with caps, at least try and be consistent.
catharine
2016-10-23 09:58:47 UTC
sinner_saved_by_his_grace777 i'd be a sinner until eventually I die Don, in spite of the indisputable fact that Christ calls us monks and saints in Christ Jesus, at the same time as it includes being something i want to assert why i'm what i'm and it really is because of his present of grace. Edit: I in simple terms realized that the question became , IF GOD despatched you digital mail, ha. ok, then i ought to assert it to be. Your_bought1_who_is_waiting_for_you If he's sending me the e.mail i ought to ought to make it particular for him.
anonymous
2012-04-30 19:33:52 UTC
I agree with the two above. From my past experience, your $to and $from variables need to also be real emails to actually work.


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