jagguy Posted July 30, 2007 Share Posted July 30, 2007 How do i send a email message via php? Quote Link to comment https://forums.phpfreaks.com/topic/62452-send-email/ Share on other sites More sharing options...
dooper3 Posted July 30, 2007 Share Posted July 30, 2007 using the mail() function. Basic parameters are: mail(to, subject, message, extra stuff), so you can have something like the code below to send an email to derek with the subject "i like bananas" and the message body text being (fish is good with cheese". <?php $to="derek@somemail.com; $subject="i like bananas"; $message="fish is good with cheese"; $from="jagguy@phpfreaks.com"; mail($to, $subject, $message, "From: $from"); ?> And it's as easy as that! For more info on the mail function, go to... http://uk2.php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/62452-send-email/#findComment-310823 Share on other sites More sharing options...
jagguy Posted August 2, 2007 Author Share Posted August 2, 2007 This does nothing when i run from my localhost on my pc? I check my mail and it doesn't get it. What do I do if the mail fails as how can i get a message to say the email wasn't sent? <?php $toemail="mymail9@hotmail.com"; $subject="KSC REgsitration"; $message="Your account has been activayed and you are read to use the KSC website "; //$message.=" \n login ".$log." \nPassword :".$pwd; $from="jagguy@phpfreaks.com"; echo "yesy"; mail($toemail, $subject, $message, $from); echo "yesy"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/62452-send-email/#findComment-313827 Share on other sites More sharing options...
ToonMariner Posted August 2, 2007 Share Posted August 2, 2007 you need to set the SMTP setting in your php.ini file to your isp's mail server... Quote Link to comment https://forums.phpfreaks.com/topic/62452-send-email/#findComment-313831 Share on other sites More sharing options...
jagguy Posted August 4, 2007 Author Share Posted August 4, 2007 I uploaded the file on a website and run it . It works fine. Now what about headers on my email. My ISP just contacted me about unauthorised emails. Now I didn't do anything other than 1 email sent like below(no spam or anything just 1 email). I believe the email was detected because it had no headers and was thought to be suspicious. What headers do i need to make it official. $to="derek@somemail.com; $subject="i like bananas"; $message="fish is good with cheese"; $from="jagguy@phpfreaks.com"; mail($to, $subject, $message, "From: $from"); Quote Link to comment https://forums.phpfreaks.com/topic/62452-send-email/#findComment-315439 Share on other sites More sharing options...
mrjcfreak Posted August 4, 2007 Share Posted August 4, 2007 There are a number of security things you need to be aware of if you want to be able to set the to/from addresses addresses with submitted form values. You need to 'clean' them or people can inject nasty things in your headers, hi-jack your mail form and send spam everywhere. As always with coding,it's important to read up on the tools you are using to check how to use them properly... Headers will 'lend credence' to your message, but it's not the full story. Firstly: mail set up: My host requires me to add another -f switch to my mail() command as a precaution. Second: It will also refuse to send messages from my scripts if the 'from' address is not one they host. (i.e. if I claim to be sending mail from hotmail.com it will fail) for example if I set up a feedback from so that a visitor can send me an email,and I set their email address as the from address, the message will not be sent. Thirdly, depending on how your host has things set up, mail you send using PHP might come from a different IP than the IP address listed in the official MX (mail exchange) records. If this is the case (and there really is nothing you can do about it) then so called 'reverse dns-lookup' spam testing will fail. That is,all your messages will be marked as Spam I *believe* that Hotmail and other major providers have been using this spam checking protocol for the last year or so, with the upshot that any mail you send to Hotmail users will be marked as Spam. The amnual page I linked to has loads on headers, explained more concisely than I can eloquently do here. Quote Link to comment https://forums.phpfreaks.com/topic/62452-send-email/#findComment-315448 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.