Send mail using PHP

ArditA

New member
Joined
May 17, 2010
Messages
4
Hallo, I'm quite knew and learning.
I'm building my new site, in this site I made a contact form, so customers can contact me.


It should be possible using the PHP command "mail" to send a mail to an address defined after the mail command. PHP should send this mail fram the [email protected] mail address.

However this does not seem to work. I suspect that it has to do with the fact that the server only supports incoming post not outgoing.

If I look at the DNS mannegment it states this for PO and SMPt:

ftp A 92.48.206.81
localhost A 127.0.0.1
mail A 92.48.206.81
pop A 92.48.206.81
smtp A 92.48.206.81
www A 92.48.206.81

How can I change the smtp so I can use the smtp of my provider for the outgoing mail and ad the username and password required for that smtp account??

Best regards Ardita
 
Hi Ardita,

It depends on what your hosting provider has allowed on their server. In most cases php would allow mail and use the default account.

Contact your provider and check with them what is allowed on your account.
 
Thanks I did, they refered me to this page with this excample:

Adapt the example below for your needs. Make sure you change the following variables at least:
from: the email address from which you want the message to be sent.
to: the recipient's email address and name.
host: your outgoing SMTP server name.
username: the SMTP user name (typically the same as the user name used to retrieve mail).
password: the password for SMTP authentication.
Sending Mail from PHP Using SMTP Authentication - Example

1 <?php
2 require_once "Mail.php";
3
4 $from = "Sandra Sender <[email protected]>";
5 $to = "Ramona Recipient <[email protected]>";
6 $subject = "Hi!";
7 $body = "Hi,\n\nHow are you?";
8
9 $host = "mail.example.com";
10 $username = "smtp_username";
11 $password = "smtp_password";
12
13 $headers = array ('From' => $from,
14 'To' => $to,
15 'Subject' => $subject);
16 $smtp = Mail::factory('smtp',
17 array ('host' => $host,
18 'auth' => true,
19 'username' => $username,
20 'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>

I tried this, inserting my correct data, but it gave me the next error message!!

Fatal error: Class 'Mail' not found in /home/ardita/domains/ardita.nl/public_html/Mail.php on line 16
 
No its not. If it is then why is there a require_once line to a Mail.php
 
Back
Top