One of the nice aspects of working in a universitary environment is, that you can take advance of many nice little things. For example, you can send free SMS via the Switch Mailgateway (http://www.switch.ch/mail/)
To do so, I wrote a simple PHP script, wich enables me to send SMS via a little Textbox through a Website. I used the PEAR Framework to implement the mailing- function. For readability I stripped away the HTML forms and JavaScript functions, wich limited the form’s capacity to the SMS- usual 160 characters.
<?php require_once('Mail.php'); if (isset($_POST['smsor_message'])) { $options = array ( 'host' => 'smtp.unibas.ch', 'auth' => false, ); $mailer = Mail::factory('smtp', $options); if (true === PEAR::isError($mailer)) { die ($mailer->getMessage()); } $headers = array( 'From' => 'me@unibas.ch', 'To' => $_POST['smsor_to']."@sms.switch.ch", ); $res = $mailer->send($_POST['smsor_to']."@sms.switch.ch",
$headers,
$_POST['smsor_message']); if (true === PEAR::isError($res)) { die ($res->getMessage()); } echo "Message <br>\n<i>".$_POST['smsor_message']."</i><br>\n
sent to <i>".$_POST['smsor_to']."</i><br>\n"; echo "<br><hr><br>"; } ?>
Hello
I’ve tried your script! It sounded nice, but I couldn’t make it work:
SMTP: Invalid response code received from server (code: 530, response: #5.7.0 Must issue a STARTTLS command first)
I think I finished the script properly, but I’m pretty sure I need some special authentification (maybe they changed it in those 2 years). You have any idea how to fix this? I have never worked with PEAR before (but a lot with PHP).
Greetings
I made it! If someone needs the code, this is what you need:
$smtpinfo[“host”] = “smtp-ext.unibas.ch”;
$smtpinfo[“port”] = “25”;
$smtpinfo[“auth”] = true;
$smtpinfo[“username”] = “UNI LOGIN”;
$smtpinfo[“password”] = “PASSWORD”;
Source:
http://www.cyberciti.biz/tips/howto-php-send-email-via-smtp-authentication.html
@andreas
Hi Andreas.
Thanks for you comment. Quite helpful if you want to send SMSes from outside the Uni network :)