SMTP and headers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomE
Forum Newbie
Posts: 19
Joined: Tue Jul 12, 2005 7:26 am
Location: Liverpool

SMTP and headers

Post by tomE »

I simply don't understand what this means can anyone explain? I am trying to test an email script locally with the form submitting to a yahoo email address. does anyone know how to rectify this?

There also appears to be a problem with the header, although its nothing i can see.

here is the code

Code: Select all

<?
$name=$_REQUESTї'name'];
$email=$_REQUESTї'email'];
$comments=$_REQUESTї'comments'];
$to=&quote;me@yahoo.co.uk&quote;;
$message=&quote;$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email&quote;;
(mail($to,&quote;Practice Feedback form &quote;,$message,&quote;From: $email\n&quote;));
header ( &quote;Location: http://localhost/contact_redirect.html&quote; );
?>
Here is the error warning

Code: Select all

Warning: mail(): Failed to connect to mailserver at &quote;localhost&quote; port 25, verify your &quote;SMTP&quote; and &quote;smtp_port&quote; setting in php.ini or use ini_set() in c:\inetpub\wwwroot\PHP\mail.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\PHP\mail.php:12) in c:\inetpub\wwwroot\PHP\mail.php on line 13
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'm assuming you know what an SMTP server is and that you at least think you have one running on the PC?

If not, find out what your SMTP server is from your ISP and then set it in php.ini under the SMTP directive ;)

It can't find a running SMTP server on your PC that's all.
tomE
Forum Newbie
Posts: 19
Joined: Tue Jul 12, 2005 7:26 am
Location: Liverpool

Post by tomE »

i don't think i have one running no. How can you tell if i have one or not? Are there any security measures i should be taking to stop this illicit viewing of my OS?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

tomE wrote:i don't think i have one running no. How can you tell if i have one or not? Are there any security measures i should be taking to stop this illicit viewing of my OS?
Excuse me? :? Viewing your PC? I just asked if you had an SMTP server running because you'll need one to send mail from an SMTP server on localhost:25

Here... when you configure outlook, evolution, or whatver email software you send emails from what server address do you put in the SMTP settings (to send email)?

Once you know that, open php.ini and find the line

Code: Select all

SMTP=localhost
Change localhost to the address of your SMTP server. If you're unsure then just try:

smtp.<your_isp's_domain_here>.com --> this is fairly standard but will vary between ISP's.

If you don't know what your SMTP server is or what one does I suggest googling for "SMTP servers" or asking your ISP before attempting to send an email through one ;)
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

On php/windows you can only send mail via servers that don't require a password (not many).
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

http://phpmailer.sourceforge.net/ has a SMTP class too ;))
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

bokehman wrote:On php/windows you can only send mail via servers that don't require a password (not many).
Sorta true.. php's mail() function doesn't support it, but there is a pear class that does, and there is also the always-fantastic phpmailer. In both cases you can.

However, the original poster sounds like he doesn't have a smtp server running on his machine, so cannot send as a result.

Also, if he sets it to use his isp's smtp server, they have to allow such things, which isn't always true.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

For just these cases I have write a script so you don't need a mail server at all. It just sends the mail to the remote mailserver directly. That way no username or password is required and there are no worries configuring your mail server because you don't use it.
Post Reply