• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3102
  • Last Modified:

How to setup PHP sendmail or SMTP for home computer behind cable modem using Fedora Linux

Hi, I am using a home pc with Fedora Linux installed. I am trying to send email messages with a PHP script running under Apache server. I was wondering if it is possible:

1. To send emails using sendmail using my pc behind a home user cable modem (optimum online)?

2. If it's not possible using sendmail, how can I set it up to use SMTP provided by my ISP just like I use with email clients?


Thank you.
0
santocki
Asked:
santocki
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
nizsmoDeveloperCommented:
Here are some useful information you are looking for:

http://email.about.com/cs/phpemailtips/qt/et021802.htm
http://email.about.com/cs/phpemailtips/qt/et022802.htm


Alternatively a custom sendmail function which is probably faster than the mail() function built into PHP:

 function sendmail($ToName, $ToEmail, $FromName, $FromEmail, $Subject, $Body, $Header)
{
$SMTP = fsockopen("smtp.sitename.com", 25);

$InputBuffer = fgets($SMTP, 1024);

fputs($SMTP, "HELO sitename.com\n");
$InputBuffer = fgets($SMTP, 1024);
fputs($SMTP, "MAIL From: $FromEmail\n");
$InputBuffer = fgets($SMTP, 1024);
fputs($SMTP, "RCPT To: $ToEmail\n");
$InputBuffer = fgets($SMTP, 1024);
fputs($SMTP, "DATA\n");
$InputBuffer = fgets($SMTP, 1024);
fputs($SMTP, "$Header");
fputs($SMTP, "From: $FromName <$FromEmail>\n");
fputs($SMTP, "To: $ToName <$ToEmail>\n");
fputs($SMTP, "Subject: $Subject\n\n");
fputs($SMTP, "$Body\r\n.\r\n");
fputs($SMTP, "QUIT\n");
$InputBuffer = fgets($SMTP, 1024);

fclose($SMTP);
}

You will need to customize for your own needs.
0
 
Steve BinkCommented:
Be aware that many ISPs block port 25 (SMTP) for exactly this reason.  They don't want every joe-schmoe running an email service through their network.  You should probably talk to your provider to find out how this idea is affected by your terms of service.  You can do an informal test by forwarding port 25 to your fedora box, then browsing to http://canyouseeme.org.  Be sure to remove the forward afterwards, or you'll be spamming the world in no time.

Fedora comes with sendmail pre-installed.  If you can use the mail command from the prompt and successfully send/receive mail to an external account, you should be good to go.

0
 
hernst42Commented:
> 1. To send emails using sendmail using my pc behind a home user cable modem (optimum online)?
no most mails will be rejected when delivered from dial-ups or directly marked as spam. So directly delivering the mails from your home-computer is no good idea.

> 2. If it's not possible using sendmail, how can I set it up to use SMTP provided by my ISP just like I use with email clients?
Use a mailer class in PHP which handels the SMTP-Auth at your providers side like
http://swiftmailer.sf.net
http://phpmailer.sf.net
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
santockiAuthor Commented:
Thanks for the replies, but I am trying to find a simple solution like setting up a default SMTP server for all of my PHP scripts I am testing, which are the scripts developed by others so I can test them fully before uploading them to my server at the hosting company. So I won't add any kind of emailing routine by myself, because they already exists in these scripts.

Is it possible to set a default SMTP server at php.ini or http.conf?
0
 
santockiAuthor Commented:
Note: Setting up a default SMTP means to use my ISP's SMTP address, not to setup a SMTP on my computer.

I have tried to send messages using PHP's default configuration that uses sendmail, but it won't work.

Thank you.
0
 
nizsmoDeveloperCommented:
0
 
hernst42Commented:
> Is it possible to set a default SMTP server at php.ini or http.conf?

not for unix. You need to change your mailer-configuration to forward all mails it receives via sendmail to deliver at your ISP's mailserver. Check the docu for your mailserver about the relay host (or how to setup your mailings-system as a smart-host).

On my SuSE-box i have something like this for postfix:

#
# Should we use a mailrelay?
# NOTE: ALL mail that is not considered to be my destination
# (POSTFIX_LOCALDOMAINS), will be sent to this host.
# If this host is not your MX, then you have to use [square brackets]
# around the hostname, e.g. [relay.example.com]
# You may also specify an alternate port number, e.g.
# relay.example.com:26 or [relay.example.com]:26 to prevent MX lookups.
#
POSTFIX_RELAYHOST=""

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now