mail script in php
I 开发者_Python百科am hosting my web application(pnpmkt.com
) from GODADDY.com
they have given me some email account like info@pnpmkt.com. I want to send welcome message to new user's to their mail account in other mail servers like google, yahoo.for example, my mail function is-
<?php
$address = "piysuh@gmail.com";
$Subject = "PNP Solutions";
$body = "Welcome to PNP";
$mailsend = mail("$address", "$Subject", "$body.");
print("$mailsend");
?>
what other configurations are required?Any path name or server name??
Here is a wrapper function I use to send emails (text or html):
// $Sender: Sender email
// $Recipient: Recipient email
// $Subject: Email subject
// $Detail: Plain text or HTML (should include <html> and <body> tags)
// $Type: TEXT or HTML
function sendmail( $Sender, $Recipient, $Subject, $Detail, $Type )
{
switch ( $Type )
{
case "TEXT":
$Header = "From: $Sender\n";
break;
case "HTML":
$Header = "From: $Sender\n";
$Header .= "MIME-Version: 1.0\n";
$Header .= "Content-type: text/html; charset=iso-8859-1\n";
break;
}
return mail( $Recipient, $Subject, $Detail, $Header );
}
Can you clarify whether you are having trouble sending emails using this method? From what I can see, your code is good, and should operate without any problems.
I just tested this code, myself, and it works fine.
It should be noted that the mail()
function returns TRUE on success and FALSE on failure so echoing that is not a terribly useful thing to do. (You'll just get "1" if it worked and "0" if it didn't.)
If you are wanting to include more advanced features and facilities in your emails, however, you may want to look at PHPmailer, which is a PHP Class allowing for the sending of HTML Emails, changing various settings like the Sender's email address and name, etc.
精彩评论