Sending email from PHP scrip

software development


I am creating a website using PHP, and the client will be using email heavily. I need to be able to create the email and send it via my DreamHost email server without the user having to open another email client (either thick or thin client). In other words - send the email directly from the website.

I’ve poked around in the Wiki for some information and can’t seem to find it. I’ve looked at the “Mail” and “IMap” functions in PHP, but can’t seem to figure out how to set the server name so that the email goes out via my DreamHost email server.

They will be sending both Announcements using an Announcement list on the server, and ad-hoc emails populating the recipients list from their DB of clients.

I’d appreciate any help pointing me in the right direction.



References you must read:
DreamHost Wiki - SMTP Quota
DreamHost - Anti-Spam Policy

Second PHP sends messages by piping it to the MTA program (DreamHost uses Postfix). So there is no need to specify hostname for the mail server.

:cool: -//-


Thanks for the info. I had already read the policy pages; I needed that info before I ever started the project.

So anyway - I was able to use the PHP mail() command to send email to discrete email addresses - so far, so good.

I’m still having a problem with the announcement list, however. I configured a list, added my own email address, confirmed it via the email I received, and verified that it’s in the list on the Announcement list management page.

However, if I send an email via the PHP mail() command, using the announcement list (full @ path) as the recipient, it doesn’t get delivered.

Am I doing something incorrect here?



[quote]However, if I send an email via the PHP mail() command, using the announcement list (full @ path) as the recipient, it doesn’t get delivered.

Am I doing something incorrect here?[/quote]
Yes. From the DreamHost Wiki

"How do I post to my announcement list?

  1. Log in to the Account Control Panel. Select the Mail tab, and click on the Announcement Lists link.

  2. Click on the Mail link to the right of your list.

  3. Enter a return name and a subject line for your outgoing message.

  4. Write or paste the message you wish to send in the large text box.

  5. If your message is HTML-formatted, be sure to click the checkbox marked This is HTML.

  6. Click the Send Message link, and you’re done!

The only way to post to an announcement list is through this form… if you want an open discussion style email list, what you need are our discussion lists!"

So this seems to imply you would want to setup a discussion list instead. While it is possible to script accessing the DreamHost web panel, DreamHost doesn’t provide a standard API so it might break.

:cool: -//-


Thanks again, but a discussion list apparently allows anyone that’s a member of the list to use it, and we definitely don’t want that.

We have a site with about 1000 members, and the person in charge of the site wants to be able to send emails to some or all of the members. The “some” part can apparently be handled via the normal email route, but to send an email to all 1000 members seems like it would require the Announcement list.

The person in charge of the site is not going to want to have to open a new browser window and navigate to the Announcement list screen. I’d rather she not have access to the admin screens for my other websites.

What’s my best approach then? You mentioned that it’s “possible” to script the screen - realizing that it could change at some point in the future, do you have any info on that? Do you have any other suggestions for scriptable “one-way” emailing to about 1000 people that won’t break the rules? She will be sending HTML mail.

Thanks again…


I’m not sure why you say that. The software allows you to restrict the ability to post messages to certain people.

Scripting access to the web panel is an advanced topic. Obvious it includes developing a web client that can access a secure web site, and this can be done with PHP and its cURL support. AFAIK there is no ready-to-use script available to do this.

Besides using the discussion list provided by DreamHost, you can outsource it at a price. I know of a company that offers it for $25/month and $3 per 1000 messages.

:cool: -//-


okay - so Discussion Lists it is…

I looked through the control panel and I am still not clear on a few things:

  1. How do I restrict people from being able to send emails to the Discussion List?

  2. How do I programmatically add names to the list? As with the Announcement List, I don’t want the site master to have to do it via the DreamHost site; I want the functionality to add addresses to the list to be embedded in the site I am coding for them.

Thanks for the info, your time, and your patience…


Until yesterday, my PHP script was able to send emails. But not anymore. The script wasn’t changed, and i have no idea what to do now. The script is sending trial license keys for my product for those whe requested it ovet

The mail sendig script is something like this:

$subject = ‘Pageflip5 Trial License Key & download link’;
$message = ‘Hi,’. “\r\n\r\n” .
‘Thanks for Your interest in Pageflip5.’. “\r\n” .
'Your unique Trial License Key: '.$key. “\r\n” .
‘Download link:’. “\r\n\r\n” .
‘Best regards,’. “\r\n” .
‘Pageflip Team’. “\r\n” .
‘Iparigrafika Ltd.’;
$headers = ‘From:’ . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();

mail($emailaddr, $subject, $message, $headers);

Any idea why the emails can’t be sent anymore?


Open a ticket and ask support. What’s likely happaned is something broke or got flooded on your individual server.


Thanks for the tip, i just did it!


It’s also possible your server got blacklisted. If that’s the case the fastest thing to do is reconfigure your script to send the mail using smtp and logging into a valid mail account on your domain.


It’s just my opinion but PHP script are never the good way to send emails. Use SMTP protoco, much safier.