简体   繁体   中英

Why isn't this PHP emailing script working?

I'm having a bit of an issue with PHP emailing from a HTML form. Can you guys help me? I'm getting the error in 'else' in the $sent variable.

The directories are made like this:

Site
    --> HTML
            --> webpage.html
    --> PHP
            --> emailform.php

The fact that it's finding the PHP file seems like that part's ok. I'm not sure what causes it to not send the email though. I'm using a free web host. Maybe this is the issue?

HTML:

<form method="post" action="../PHP/emailform.php" style="width:300px; float:left; margin-top: 50px;">
<div><div>
Navn: <input type="text" name="navn" style="float:right;"/>
</div><br /><div>
Telefonnummer: <input type="text" name="telefon" style="float:right;"/>
</div><br /><div>
Email: <input type="text" name="email" style="float:right;"/>
</div><br /><div>
Bosted: <input type="text" name="bosted" style="float:right;"/>
</div><br /><div>
iPhone-modell: <select name="iphonetype" style="float: right;">
<option value="iphone2G">iPhone 2G</option>
</select>
</div></div><br />
Reparasjoner:<div style="float:right; clear: both;">Bytte LCD/skjerm (1200,-) 
<input type="checkbox" name="lcdglass" />
</div><div style="float:left; padding-top:12px;">
Andre kommentarer: <textarea name="kommentarer" cols="34" rows="3"></textarea>
</div><br /><div style="float: left; margin-top: 12px;">
<input type="submit" name="send" value="Send henvendelse" />
</div>
</form>

PHP:

<?php
$to = "email@gmail.com";
$subject = $_REQUEST['iphonetype'] . " reparasjon fra mysite.no";
$email = $_REQUEST['email'];
$message = "Navn: " . $_REQUEST['navn'] . "\nTelefonnummber: " . $_REQUEST['telefon'] . "\nBosted: " . $_REQUEST['bosted'] . "\nLCD/Glass " . $_REQUEST['lcdglass'] . "\nKommentarer: " . $_REQUEST['kommentarer'] . "\n\nMvh,\n" . $_REQUEST['navn'] . "\n" . $_REQUEST['telefon'];
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Takk. Din henvendelse er mottatt. Du kan fovente å få svar innen 24 timer."; } else {print "Dessverre oppstod det en feil. Kontakt email@gmail.com direkte for reparasjon."; }
?>

I really hope you guys can help me find the error. Thanks!

awardspace.com requires you to use one of your eMail-Accounts, otherwise their SMTP won't let you send mails.

See HERE :

$mymail = “youremail@account.com”;
$headers .= “From:Contact Form <$myemail>\r\n”;
$headers .= “Reply-To: $name <$email>\r\n”;
mail($mymail, $subject, $message ,$headers);

Try to use following headers:

$headers = "From: $email";
$header.= "MIME-Version: 1.0 ";
$header.= "Content-type: text/html \r\n";

I hope it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM