PHP mail() help

software development

#1

I am a bit stuck. I wrote code for a members login page and after they register I want them to be able to get an email with their login info.

Problem is I do not know how to set the mail function to use the dreamhost smtp settings. here is my code any help on where or how to set the smtp up would be appreciated.


$to = ‘$memEmail’;
$subject = ‘Your Membership’;
$message = 'Dear $memFirstName $memSurName,
You are now registered at our website, http://www.nerodb.com !

To access your membership and character sheets, you will be able to login with the following information:
Username: $userName
Password: $userPassword
Please keep this username and password in a location that is easily accessible by you.

Thanks!
Webmaster

This is an automated response, please do not reply!’;
$headers = “From: noreply@nerodb.com\r\n” .
‘X-Mailer: PHP/’ . phpversion() . “\r\n” .
“MIME-Version: 1.0\r\n” .
“Content-Type: text/html; charset=utf-8\r\n” .
“Content-Transfer-Encoding: 8bit\r\n\r\n”;

mail($to, $subject, $message, $headers)or die(‘something went wrong’);


#2

SMTP should be automatically setup. the mail() function should work without any setup required.

si-blog
Max discount on any plan with promocode SCJESSEYTOTAL


#3

hmm well its not working. :slight_smile:

I am able to run the script and get the test message that is hardcoded in but it won’t send me an email. All the settings seem to be right but something is not calling up my email server, so I figured I had messed up on a mail setting.


#4

There are a few things you could do differently…

See the examples in the wiki.

And make sure you follow the link regarding Email Injection.

Regards,
Rudy


#5

Does this work for you?

<?php $siteEmail = 'noreply@nerodb.com'; $to = '$memEmail'; $subject = 'Your Membership'; $message = 'Dear $memFirstName $memSurName, You are now registered at our website, http://www.nerodb.com ! To access your membership and character sheets, you will be able to login with the following information: Username: $userName Password: $userPassword Please keep this username and password in a location that is easily accessible by you. Thanks! Webmaster This is an automated response, please do not reply!'; mail($to, $subject, $message, "From: $siteEmail") ?>

#6

[quote]$to = ‘$memEmail’;
$subject = ‘Your Membership’;
$message = ‘Dear $memFirstName $memSurName’[/quote]
You can’t get the value if PHP variables are inside single quotes. Try to use double codes like this:

$to = [color=#CC0000]"[/color]$memEmail[color=#CC0000]"[/color];
$subject = [color=#CC0000]"[/color]Your Membership[color=#CC0000]"[/color];
$message = [color=#CC0000]"[/color]Dear $memFirstName $memSurName[color=#CC0000]"[/color];

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here


#7

crap I wish I would have spotted that first.:slight_smile:

Thanks that fixes it.