Need help with sending mail in PHP

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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Need help with sending mail in PHP

Post by vigge89 »

Ive created a Contact form, with this code:

Code: Select all

<?php

//Check for empty fields
if(isset($_POST['email'])) {
if($_POST['email'] <> "") {
if($_POST['subject'] <> "") {
if($_POST['message'] <> "") {

$to = "vigge19@hotmail.com";
$from = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$headers  = "From: $from\r\n";

$success = mail($to, $subject, $message, $headers);

if($success) $msg = "The email was succesfully sent.";
else $msg = "An error occurred when sending the email.";

//If the user have forgot a needed field, tell him:
} else { $msg = "You need to have a message!" };
} else { $msg = "You forgot the subject field" };
} else { $msg = "You must fill in the email field" };
};

//Print back button and content of page and message:
echo "$msg<br>
<input type="button" value=" back to about page " onClick="history.go(-2)">
";

?>
The form itselft is on another page, ill reply with the code for it if needed,
But when i test it, i get a Parse error saying:
Parse error: parse error, unexpected '}' in C:\xampp\htdocs\source\mail.php on line 22
What have i done wrong?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

} else { $msg = "You need to have a message!" };
} else { $msg = "You forgot the subject field" };
} else { $msg = "You must fill in the email field" };
// missing ;'s
} else { $msg = "You need to have a message!"; };
} else { $msg = "You forgot the subject field"; };
} else { $msg = "You must fill in the email field"; };
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

JAM wrote:

Code: Select all

} else { $msg = "You need to have a message!" };
} else { $msg = "You forgot the subject field" };
} else { $msg = "You must fill in the email field" };
// missing ;'s
} else { $msg = "You need to have a message!"; };
} else { $msg = "You forgot the subject field"; };
} else { $msg = "You must fill in the email field"; };
oh, do u need to do that, k, ill test it now
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

a question; how do u set up the SMPT settings? I wanna know if its easy, becuase im not sure what it is or if the contact form will work when i upload it onto my webhost. :?:
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

http://se.php.net/manual/en/ref.mail.php
SMTP string

Used under Windows only: DNS name or IP address of the SMTP server PHP should use for mail sent with the mail() function.
smtp_port int

Used under Windows only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25. Only available since PHP 4.3.0.
sendmail_from string

Which "From:" mail address should be used in mail sent from PHP under Windows.
sendmail_path string

Where the sendmail program can be found, usually /usr/sbin/sendmail or /usr/lib/sendmail. configure does an honest attempt of locating this one for you and set a default, but if it fails, you can set it here.

Systems not using sendmail should set this directive to the sendmail wrapper/replacement their mail system offers, if any. For example, Qmail users can normally set it to /var/qmail/bin/sendmail or /var/qmail/bin/qmail-inject.
Där ser du vilka php.ini settings som krävs för att det ska funka. Men en bra webhost behöver inga ändringar, eftersom detta fixas när de installerar PHP.

Short in english: shouldn't be needed for a good host.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

ok, i hope the host(s - maybe) im using are good then :P

tackar :D
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

have you looked at self processing forms? not all browsers are kind enought o remmeber and repopulate data. a self processing form can allow you to give them the data they submitted AND the error message.
Post Reply