I am trying to send data from a contact form to my email adress.

IT IS FROM LOCALHOST - THE SITE IS NOT ONLINE.

My form looks like this:

<form name=form1 method=post action=send_contact.php>
<p>Emne:</p><input name=subject class=input type=text id=subject size=64>
<br /><br />
<p>Forespørgsel:</p><textarea name=detail cols=50 rows=7 id=detail></textarea>
<br /><br />
<p>Navn:</p><input name=name class=input type=text id=name size=64>
<br /><br />
<p>Email:</p><input name=customer_mail class=input type=text id=customer_mail size=64>
<br /><br />
<input type=submit name=Submit value=&nbsp;Send&nbsp;> <input type=reset name=Submit2 value=&nbsp;Ryd formen&nbsp;>

My send_contact.php looks like this:

<?php
// Contact subject
$subject = $_POST['subject'];
 
// Message from sender
$message = $_POST['detail']; 

// Mail of sender

$mail_from = $_POST['customer_mail'];

// Name of sender
$name = $_POST['name'];

// Enter your email address
$to ='myemail@hotmail.com';

$headers = "MIME-Version: 1.0 . \r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 . \r\n";
$headers .= "From: $mail_from . \r\n";
$send_contact = (mail($to, $subject, $name, $message, $headers));

if($send_contact){
echo "Tak for din forespørgsel.";
header: "location(index.php)";
}
else {
echo "ERROR";
}
?>

With this code I get the following error message after i try to submit the form and send the message to my email:

Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first in C:\wamp\www\enkeltwebdesign\send_contact.php on line 21

The settings in my php.ini looks like this:


[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.live.com
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = you@yourdomain

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =

Can someone see what I am doing wrong?
I dont know if it should be smtp.live.com or pop3.live.com - And other settings might be wrong too, or?

Help highly appreciated!

Jan

It means that smtp.live.com will only send emails via an TLS connection (TLS is an upgrade from SSL).

So you might want to search google for how to configure PHP specifically for live.com. If not, you can use a PHP based SMTP class as it will allow you to put in the user/pass and TLS settings.

<form name=form1 method=post action=send_contact.php>
<p>Emne:</p><input name=subject class=input type=text id=subject size=64>
<br /><br />
<p>Forespørgsel:</p><textarea name=detail cols=50 rows=7 id=detail></textarea>
<br /><br />
<p>Navn:</p><input name=name class=input type=text id=name size=64>
<br /><br />
<p>Email:</p><input name=customer_mail class=input type=text id=customer_mail size=64>
<br /><br />
<input type=submit name=Submit value=&nbsp;Send&nbsp;> <input type=reset name=Submit2 value=&nbsp;Ryd formen&nbsp;>

You don't have quotes in your html- that will stop things from working at all until that gets fixed, I believe.

Arh i see, quotes are there, I was a little fast on writing it here.

Digi-ether:

The confusion is total now :-)

I have never heard about these things before, since i am new to php.

I might see if works when i upload my page, and check what me host has to say to the codes, as I can use there smtp to mail from.

If it was straight forward I thought it would be nice to be able to see things working on my local machine before uploading everything. But I have enough to do at the moment to dig into that world..

Thanks for your answer though, I will surely look into it when I have the time for it :-)

Something that may make configuring easier, but in the past I've seen this issue resolved by changing the SMTP setting in php.ini to the SMTP server of your ISP.

I don't think that fixes it 100% of the time (I'm sure it has something to do with your ISP as well), but it may be worth a shot. You can usually find your ISP's SMTP server address by doing a quick Google search.

It is actually harder to set up email on your localhost then your actual webserver. For one your localhost is likely windows, which doesn't have sendmail built in. The other is if you use SMTP, usually you use your servers SMTP server and your PHP script is considered to run on the local netwowrk. Many mail servers will allow local connections to the SMTP server without authentication.

The other thing is that SMTP servers do not trust IP addresses issued to regular internet subscribers (your local IP). Your local computer is also unreachable from the internet, making some verification features (spam checks) impossible to do. Your remote web server usually has an SMTP server configured for this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.