简体   繁体   中英

Simple PHP form won't send email

I'm having trouble with a form where you can register a football team for a tournament trough filling out several text-fields and click send to send the form by email to my email account. The only problem is that I can seem to figure out what I'm doing wrong, because the email wont send, at least it wont show in my inbox (I've tried several email accounts).

So, here is my html form:

<form id="form1" name="form1" method="post" action="send.php">

  <table width="276" border="0">
    <tr>
      <td width="106">Lagnavn: </td>
      <td width="386"><input type="text" name="lagnavn" id="lagnavn" /></td>
    </tr>
    <tr>
      <td>Klasse: </td>
      <td><input type="text" name="klasse" id="klasse" /></td>
    </tr>
    <tr>
      <td>Kontaktperson: </td>
      <td><input type="text" name="kontaktperson" id="kontaktperson" /></td>
    </tr>
    <tr>
      <td>E-mail: </td>
      <td><input type="text" name="email" id="email" /></td>
    </tr>
    <tr>
      <td>Telefonnummer: </td>
      <td><input type="text" name="tel" id="tel" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Spiller 1:</td>
      <td><input type="text" name="spiller_1" id="spiller_1" /></td>
    </tr>
    <tr>
      <td>Spiller 2:</td>
      <td><input type="text" name="spiller_2" id="spiller_2" /></td>
    </tr>
    <tr>

blablabla.....

with this at the end

   <tr>
    <td></td>
      <td><input type="submit" name="submit" id="send" value="Send påmeldingen" /></td>
    </tr>
  </table>
</form>

And here is my php code, send.php:

<? 

$lagnavn = $_POST['lagnavn'];
$klasse = $_POST['klasse'];
$kontaktperson = $_POST['kontaktperson'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$spiller_1 = $_POST['spiller_1'];
$spiller_2 = $_POST['spiller_2'];
$spiller_3 = $_POST['spiller_3'];
$spiller_4 = $_POST['spiller_4'];
$spiller_5 = $_POST['spiller_5'];
$spiller_6 = $_POST['spiller_6'];
$spiller_7 = $_POST['spiller_7'];
$spiller_8 = $_POST['spiller_8'];
$spiller_9 = $_POST['spiller_9'];
$spiller_10 = $_POST['spiller_10'];
$spiller_11 = $_POST['spiller_11'];
$spiller_12 = $_POST['spiller_12'];

$to = "contact@simplecityblog.com";
$subject = "Paamelding AV-cup";
$message = "Hallo!

Paamelding AV-cup!

Lagnavn: $lagnavn
Klasse: $klasse
Kontaktperson: $kontaktperson
Email: $email
Telefonnummer: $tel

Spiller 1: $spiller_1
Spiller 2: $spiller_2
Spiller 3: $spiller_3
Spiller 4: $spiller_4
Spiller 5: $spiller_5
Spiller 6: $spiller_6
Spiller 7: $spiller_7
Spiller 8: $spiller_8
Spiller 9: $spiller_9
Spiller 10: $spiller_10
Spiller 11: $spiller_11
Spiller 12: $spiller_12

Takk!";


mail($to, $subject, $message);
header('Location: index.php');
?> 

if you're going to use the SMTP server of your shared host, then you can run your mail function with simple PHP Mailer System where you give the smtp host, smtp username and smtp password and just run any example code to send the mail. BTW, I ran your code in my localhost and it works fine. It might be a server issue.

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