My PHP account is hosted by the university. I want to send email to my gmail account and not the account tied to my PHP account. Is this possible?

I know how to send email in PHP. I want to send email using a different email account.

mail ('to@someone.com','TEST','HELLO','FROM:email@addressofmychoice.com');

Member Avatar for diafol

Most self respecting hosts deny you the right to do this as you could be sending spam from an anonymous(ish!) address. My favourite host insists that your email 'from' has the same domain address.

Member Avatar for diafol

Thanks Allin. It may be of use in the future.

However, at the moment, I use the email of the domain - it gives the recipient confidence in the mail if it shows the same name. I just have forwarders to my main account from the domain accounts. Solves a lot of hassle.

I'm not familiar with the package, can it be used without the host having it installed on their server? That is, can a user just include it in their page?

It doesn't matter if you use pear or mail(), an email server configured to deny senders that do not have accounts on the mailserver will not send email with different sender addresses.

If your mail server sends email with sender addresses with accounts not on the server, then you essentially have an open relay, which will likely hinder your ability to send email as it will be marked spam, and also invite spammers to use your mail server.

commented: Aha - sense at last. Thought I was losing the plot. +6
Member Avatar for diafol

Thanks DE, I was wondering if a host's attempts to prevent spamming could be so easily circumvented.

I may be wrong, but when using Pear to send email, the script connects to the mail server and the mail is sent from there and not the server that is hosting the script.

I may be wrong, but when using Pear to send email, the script connects to the mail server and the mail is sent from there and not the server that is hosting the script.

You're definitely right. Pear Mail class allows you to connect to an SMTP server and send email (it can also send email from the local machine via sendmail, like PHP does on linux). However, even if you connect to a remote host, it will not send email addressed from another host, it will only send email for domains it controls. You have to log into that domain, and send email from your own account.

After reading the original post, I think what the poster wants is to send email addressed from their gmail account? If so then yes, use Pear Mail or another SMTP Mailer.

Here is the gmail.com SMTP docs:
http://mail.google.com/support/bin/answer.py?answer=13287

Gmail forces SSL, so here's an untested example using SSL (change user and pass to your own):

require_once "Mail.php";

$config = array(
'host' => "ssl://smtp.gmail.com",
'IDHost' => "gmail.com",
'port' => 465,
'auth' => true,
'username' => "youremail@gmail.com",
'password' => "yourpassword"
);

$SMTP_Mailer = Mail::factory('smtp',$config);

$from = "Testuser <testuser@gmail.com>";
$to = "Jon Doe <jon@doe.net>";
$subject = "Hi!";
$body = "Hi,nnHow are you?";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);

$result = $SMTP_Mailer->send($to, $headers, $body);

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

Based on example at: http://forums.codewalkers.com/pear-packages-47/smtp-login-to-gmail-won-t-work-47285.html

Note: You need a gmail account. You can't send email through Gmail without one. It is a good example of a server configured not to allow you to spoof the sender address.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.