简体   繁体   中英

Sending mail on PHP using LAMP

I have been trying for awhile now to send mail using PHP, and I can't seem to get it to work.

I looked at the tutorials, and they make it seem simple enough. Yet, it seems to actually require more work than what is mentioned. Through research (to make this short), it seems that instead of the "From: " header actually having the address I give to it, it seems that... sendmail replaces it or something with daemon@ubuntu? Ok, even if I don't include a header I still get spam from my gmail account from the daemon@ubuntu thing (I am running ubuntu on a vm, and sending mail to my gmail account). I guess this could explain why I incessantly get errors when I try to send mail saying how there is an error in the "MAIL FROM command".

So before I get myself involved with messing around with sendmail, is this the (likely)culprit of the daemon@ubuntu nonsense? The tutorials make mention of having things like sendmail, but they really don't go into any details of what to do with them. I did make sure that sendmail is being used in my php configuration file.

I have heard of alternative mail servers like PHPmail or something like that. I really don't want to get involved in installing and configuring more software unless I really have to. So unless you guys really think sendmail isn't worth it, I would prefer advice on sendmail if it is the problem.

Thank you for your time.

edit: I am using the PHP mail() function on an Ubuntu vm by VMware Player.

So someone wanted to see my code. I somewhat wanted to avoid this simply because I tried many different possibilities. I will just include what I have in my file right now:

<?php
                    $myEmail    = "####@gmail.com";
                    $fromAddr   = $_POST['sender-email'];

                    $headers    = "MIME-Version: 1.0\r\n";
                    $headers   .= "Content-type: text/html; charset=iso-8859-1\r\n";
                    $headers   .= "From: $fromAddr\r\n";
                    $headers   .= "'X-Mailer: PHP/'" . phpversion() . "\r\n";
                    $message    = $_POST['message'];

                    $status     = mail($myEmail, $_POST['subj'], $message);

                    if($status) {
                        echo "Your message has been sent, " .$fromAddr. "!";
                    }
                    else {
                        echo "An error occurred while trying to send the mail.";
                    }
                ?>

The MIME type thing, and Content-type thing I added later on. I have tried this without them. I have also tried sending mail without using any headers at all, and still apparently get the daemon@ubuntu thing. Also, I edited out my e-mail address to post the code on here. Ok I guess I should add this too: I am getting the data from an HTML form from another page. On submit, I come to this php page where it grabs that data and then sends the email (this isn't for anything professional, I am just doing this to learn more about web stuff).

我认为此链接可以帮助您http://www.thewireframecommunity.com/node/39此链接可以帮助您安装ssmtp以使用php邮件功能发送电子邮件

Postfix is a very easy to use and install email server, in my experience. You need an email server installed and configured before you're able to send email on your localhost.

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