Help Setting up SendMail on Fedora 17

Edit:

This is a continuation from http://www.sitepoint.com/forums/showthread.php?992305-Need-help-implementing-an-idea&p=5345386#post5345386, the issue the OP now has is setting up SendMail on his local Linux server which is running Fedora 17. I’m not all that familiar with Fedora, so if you have expertise, please lend a hand if you are able.

Okay, you can remove the echo and die statements now, the process of inserting and updating is working as expected :slight_smile:

Now on to e-mail.

  1. Are you running PHP on a local server? ie: Your PC, or on a remote server?
  2. Is it a Windows Server or Linux Server?
    2a) If Windows, are you using Apache or IIS?
  3. Do you know your SMTP information for your school’s email server?
    3a) Do you know the SMTP server name/address? usually smtp.mydomain.com
    3b) Do you know if a username and password are required for sending e-mail through the smtp server?
    3b1) If Yes, do you know what the username and password are?

okay, and what about the

//After teacher has entered marks…
$message =<<<EMAIL_MESSAGE
'Dear Student, for your information, scores for your most recent examination have been uploaded. Please visit Med Buddy to view your score. Thank you.
EMAIL_MESSAGE;

should it stay there/?

well,
1.i m running it on my localhost
2.linux server
3. nope, i don’t know the SMTP information for the schools email server… …

Yes, that top part is called HEREDOC, it allows you to build a string of output much easier than using string concatenation (Granted that first ’ shouldn’t be there).

Okay, so you are running on linux, which means you need to setup sendmail on your linux machine. What distro are you using?

distro??sorry, what’s that?

Debian, Ubuntu, Fedora, CentOS, etc. Which distribution of linux are you using?

oh, fedora i guess…

You guess? :lol:, best answer I’ve had from someone who is running a local linux server :smiley:

Try running “uname -r” from the command line/terminal/konsole (whatever you may have on your setup)

lol… :smiley: i got this, 3.6.2-4.fc17.i686

Okay, definitely fedora version 17. :smiley:

First I’d start with:
http://richardwillia.ms/blog/2011/09/allow-php-to-send-mail-in-fedora

If that doesn’t work, may have to install PHPMailer and use that instead of mail()

how do i test if it worked?? and do i enter those commands

$ setsebool -P httpd_can_sendmail 1
$ /etc/init.d/httpd restart

in my terminal???

it says command not found

okay, that is good and bad, that tells me you don’t have SELinux setup, which means I don’t have to worry about additional security trying to figure out how to get this setup on Fedora :lol:

On a side note, I’m going to split this tread again, and move this SendMail configuration process to the Server Configuration forum (where it will hopefully get more help).

lol, you got me there… i was wondering instead of configuring stuff, isnt there a way we could send mail through some free smtp, or gmail (my gmail account)??

You can try using PHPMailer

First run

yum install php-PHPMailer

Then check out the examples on this page:
http://stackoverflow.com/questions/1735966/how-to-use-php-mail-on-fedora

wait, so do i like copy all of this

require_once(‘…/class.phpmailer.php’); ///WHERE IS THE LOCATION FO THIS FILE?
$mail = new PHPMailer(true);

$mail->IsSMTP(); ////////////////////////SHOULD I LEAVE IT LIKE THIS??

try {
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = “tls”; // sets the prefix to the servier
$mail->Host = “smtp.gmail.com”; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = “yourusername@gmail.com”; // GMAIL username
$mail->Password = “yourpassword”; // GMAIL password

//This is the “Mail From:” field
$mail->SetFrom(‘name@yourdomain.com’, ‘First Last’);
//This is the “Mail To:” field
$mail->AddAddress(‘whoto@otherdomain.com’, ‘John Doe’);
$mail->Subject = ‘PHPMailer Test Subject via mail(), advanced’;
$mail->Body = “Hi!

This is my first e-mail sent through PHPMailer.”;

$mail->Send();
echo "Message Sent OK<p></p>
";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}

into where i currently have mail($studentEmailAddress, ‘New Scores Uploaded!’, $message);???

Yes, and no.

First, I’d put all of that into a separate file for testing purposes, then we’ll eventually extract it into a more reusable format once it is working.

If you ran the yum statement, I believe you can just put require_once(‘class.phpmailer.php’); but you may need to restart the httpd service.

If that doesn’t work, you can download it from http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/detail?name=PHPMailer_5.2.4.zip&can=2&q=

Extract the download into your php script folder hiearchy, and include it in your class.phpmailer.php file

Leave the IsSMTP (especially if you plan to use gmail to send your communication).
Update the appropriate auth variables.
Run the script.
Once it sends you an e-mail, let me know and I’ll help you extract it to hide a lot of the common components so you can have a one line call to replace mail() with.

Here is another good read:
http://code.google.com/a/apache-extras.org/p/phpmailer/wiki/PHPMailer?tm=6

works perfectly now… :slight_smile: emails are going…

Great.

Okay, so now to refactor it.

function send_email($to, $subject, $message)
{
  // Paste PHP Mailer code, change
  // $mail->AddAddress('whoto@otherdomain.com', 'John Doe'); to $mail->AddAddress($to);
  // $mail->Subject = 'PHPMailer Test Subject via mail(), advanced'; to $mail->Subject = $subject;
  // $mail->Body = "Hi! \
\
 This is my first e-mail sent through PHPMailer."; to $mail->Body = $message;
}

Then where you have mail(), you can replace the word mail with send_email

k, but there was one little thing i thought would be nice if we do it,

in this part of the php mailer code,

$mail->Subject = ‘New Scores Uploaded’; i wished to replace “New Scores” with $_POST[“subject”]… but it gave me some ugly error about “”" apostrophes and stuff, what is the right way to go about th is??