Viewed   132 times

I am using PHP on a website and I want to add emailing functionality.

I have WAMPSERVER installed.

How do I send an email using PHP?

 Answers

1

Using PHP's mail() function it's possible. Remember mail function will not work on a Local server.

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "rn" .
    'Reply-To: webmaster@example.com' . "rn" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> 

Reference:

  • http://php.net/manual/en/function.mail.php
Thursday, December 15, 2022
3

The PHP mail() function is for sending mail via Sendmail. If you want to use some SMTP server, you can use Zend_Mail which makes this thing very easy: http://framework.zend.com/manual/en/zend.mail.html

Using Zend_Mail you only need to write something like this:

$config = array('auth' => 'login',
            'username' => 'myusername',
            'password' => 'password');

$transport = new Zend_Mail_Transport_Smtp('mail.server.com', $config);

$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('sender@test.com', 'Some Sender');
$mail->addTo('recipient@test.com', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send($transport);

The above handles authentication for you and sends a mail.

Saturday, December 24, 2022
 
rwols
 
1

I am assuming that you know what an .htaccess file is.

You can achieve this by two methods:

Method 1:

`#1- Loads the page asdf.php but 
     displays asdf in the address bar  

RewriteBase   /site  
RewriteRule ^([^/.]+)?$ $1.php `  

Method 2:

`#2- Loads the page asdf.php and 
displays asdf.php in the address bar. 
The R flag tells Apache to redirect to the
url. 

RewriteBase   /site  
RewriteRule ^([^/.]+)?$ $1.php [R]`  

I hope this will help you.

Wednesday, October 12, 2022
 
yoz
 
yoz
1

You need to tell php to send the email as an HTML email.

Give this code a whirl....

 // Always set content-type when sending HTML email
 $headers .= "MIME-Version: 1.0" . "rn";
 $headers .= "Content-type:text/html;charset=iso-8859-1" . "rn";
Thursday, November 10, 2022
 
1

One from the PHP folder is for Command Line interaction, the other is for Apache itself (Web browser).

I use the CLI for my IDE (netbeans).

Friday, September 16, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :