Jump to content

send email


jagguy

Recommended Posts

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

Link to comment
Share on other sites

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";
?>

Link to comment
Share on other sites

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");

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
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.